jQuery onclick not getting triggered -


i have list on webpage. when clicks on list item, javascript should executed. example alert. working on empty page, example see code:

 <ul class="uniquelist">         <li id="1">clickable 1</li>         <li id="2">clickable 2</li>         <li id="3">clickable 3</li>         <li id="4">clickable 4</li>         <li id="5">clickable 5</li>     </ul>    $(document).ready(function(){     $('.uniquelist li').click(function(){        var id = $(this).attr('id');       alert(id);     });   }); 

http://jsfiddle.net/6wafk/1/

if put code in "complete" webpage lot more code, doesn't work anymore. it's little bit post code here hope has clues of need at.

the class of list off course unique, there no other elements same class.

edit: list loaded after page loaded. output of autocomplete!

if you're adding list after page load, need use on():

$(document).ready(function(){   $('body').on('click', '.uniquelist li', function(){      var id = $(this).attr('id');     alert(id);   }); }); 

body maybe exchanged ascendant selector present on page when loads - closer selector chose, less dom traversal jquery have do.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -