Closest Selector jQuery -
i'm trying select value jquery closest i'm newbie , attempts haven't been successful.
can tell me i'm doing wrong ? appreciated!
<div class="two columns"> <form class="float-right"> <input type="hidden" id="show_id" value="329"> <input type="hidden" id="user_id" value="172"> <div id="follow-button" class="button small follow-call follow-show float-right">follow</div> </form> </div> <div class="two columns"> <form class="float-right"> <input type="hidden" id="show_id" value="389"> <input type="hidden" id="user_id" value="172"> <div id="follow-button" class="button small follow-call follow-show float-right">follow</div> </form> </div>
jquery
$('.follow-show').bind('click', function() { var button = $(this); var show_id = button.closest("#show_id").val(); var user_id = button.closest("#user_id").val(); });
don't use duplicate id's, can use class instead,
you need use siblings
instead of closest
var button = $(this); var show_id = button.siblings("#show_id").val(); var user_id = button.siblings("#user_id").val();
Comments
Post a Comment