javascript - Iterate over each sibling element -
context: i'm building form , script perform ajax query, based on clicking specific button. there multiple div blocks elements of same class, , based on div block in which, button clicked, different forms processed.
as part of beginning program, have started apparently simple jquery call.
i'm trying add onclick event specific class, , trying css value of siblings of element.
error: i'm getting error stating typeerror: this.siblings undefined
.
question: proper way iterate on siblings of element using jquery?
my code:
html:
<a class="btn livestatsbtn"><span class="btn-label">get stats now</span> </a>
javascript:
$(document).ready (function() { $('.livestatsbtn').click(function(){ this.siblings.each( function () { var tx=this.css(); alert(tx); }); }); });
in jquery event handler, this
refers dom element, , not jquery object. have wrap in one:
$(this).siblings().each(function() { // ... });
also note "siblings" function, have call new jquery object wraps element siblings.
Comments
Post a Comment