I have the following html.
<input class="gallery-next1" type="hidden" value="2"><a href="#" class="gallery-next" >unu</a></input>
and the following jquery
$(".gallery-next").click(function (){
alert($(this).closest("input").val());
});
This query is showing in alert “Undefined”. Do you have any ideas why i don`t get value 2 ?
Ok now 1 is everywhere how can i bind this class to the same function and get the object rising the event?
<input class="gallery-next1" type="hidden" value="1"><a href="#" class="gallery-next" >unu</a>
<input class="gallery-next1" type="hidden" value="2"/><a href="#" class="gallery-next" >doi</a>
<input class="gallery-next1" type="hidden" value="3"/><a href="#" class="gallery-next" >trei</a>
Your markup is invalid.
<input>element doesn’t have a closing tag, so your browser tries to fix the error simply setting<a>element after<input>.Fix the markup and use either
siblings()orprev():DEMO: http://jsfiddle.net/cqwKw/