Reputation: 1362
I'm writing script which should find onclick attributes on any ancestor.
For example when I click on span.tabIdent I want get anchor onclick (I trigger it later)
HTML:
<a class="t3 lin tab-B" rel="#categoriesLinux" rev="lin" onclick="changeTab()">
<span class="tabLeft" style=""></span>
<span class="tabCenter" style="">
<span class="tabIdent" style=""></span>
</span>
<span class="tabRight"></span>
</a>
JS:
var foo,
foo2,
przodek,
parentsCount = jQuery(that).parents().length,
przodek = jQuery(that); //it's ok here
for(var ii=0; ii<parentsCount; ii++){
przodek = jQuery(przodek).parent();
foo = jQuery(przodek).prop('nodeName'),
foo2 = jQuery(foo).attr('onlick');
console.log(foo+' : '+foo2);
}
It return everywhere 'undefined'. What is wrong with this ?
Upvotes: 0
Views: 148
Reputation: 9167
You could simply do this...
$('.tabIndent').on('click', function() {
var anchor = $(this).closest('a');
console.log(anchor.prop('nodeName') + ' : ' + anchor.prop('onclick'));
});
Upvotes: 0