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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -