开发者

Better way to find Class in event.target parentnodes using jquery and javascript?

Currently, I check the target of the input box keyup event to see if it is contained within a div wit class "editorRow" using:

var $parentClass = event.target.parentNode.parentNode.parentNode.className;

Is there a better way to do this in case extra markup is added between the div and the span tags?

  <div class="editorRow">
     <li>
       <span class="wi1">
          <input type="text" value="" style="width: 80px;" name="LineItems9"  id="LineItems_9">
       </span>
     </li>  
   </div>

 

$("input").live("keyup", function(event) {

    return Give开发者_如何学GoDynamicFieldsLife(event);

});

function GiveDynamicFieldsLife(event) {

    **var $parentClass = event.target.parentNode.parentNode.parentNode.className;**

    if ($parentClass == "editorRow") {
    //Do Stuff
    }
}


$("input").live("keyup", function() {

    GiveDynamicFieldsLife(this);

});

function GiveDynamicFieldsLife(elem) {

    var $parentClass = $(elem).closest('.editorRow');

      if ($parentClass) {
        //Do Stuff
      }
}


 function GiveDynamicFieldsLife(event) {
   var $parentClass = $(event.target).parents('.editorRow');

   if ($parentClass.length) {
   //Do Stuff
   }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜