jquery - find selected child with .on method -
how can property (i.e "id"), of child selector element? im using .on() method because elemenets created ajax call. $(this).attr('id');
returns id of selector, how 1 of child selector? tried: $(this).find(':selected').attr('id');
not helps. code:
$(document).ready(function () { var userbtn = $(".userbutton"); $(".listbox").on("click", userbtn, function () { var userid = $(this).attr('id'); console.log(userid); }); });
the second parameter click handler child selector
you're passing jquery wrapped object.
$(".listbox").on("click",".userbutton",function(){ var userid=$(this).attr('id'); alert(userid); });
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.2.min.js"></script> <ul class="listbox"> <li class="userbutton" id="btn1">button 1</li> <li class="userbutton" id="btn2">button 2</li> <li class="userbutton" id="btn3">button 3</li> </ul>
Comments
Post a Comment