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

Posted by Cama on Stack Overflow See other posts from Stack Overflow or by Cama
Published on 2010-06-02T07:27:12Z Indexed on 2010/06/02 7:33 UTC
Read the original article Hit count: 161

Filed under:
|

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 GiveDynamicFieldsLife(event);

});

function GiveDynamicFieldsLife(event) {

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

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

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery