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
}
}
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
}
}
Share
Improve this question
edited Jun 2, 2010 at 7:29
Reigel Gallarde
65.3k21 gold badges125 silver badges142 bronze badges
asked Jun 2, 2010 at 7:27
Cameron McGraneCameron McGrane
4,9431 gold badge21 silver badges17 bronze badges
2 Answers
Reset to default 4$("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
}
}