Monday, February 26, 2024
 Popular · Latest · Hot · Upcoming
121
rated 0 times [  122] [ 1]  / answers: 1 / hits: 109115  / 11 Years ago, mon, september 30, 2013, 12:00:00

I have a <ul> element that dynamically generates the <li> elements and simply want to run a onclick event



<ul id=results>
<li class=device_result searchterm data-url=apple-iphone-5s>
<a href=#> Apple iPhone 5s </a>
</li>
<li class=device_result searchterm data-url=apple-iphone-5c>
<a href=#> Apple iPhone 5s </a>
</li>
</ul>


I've got the following jQuery in a $(document).ready block but it doesn't seem to work - any ideas what I'm doing wrong?



$(li .searchterm).click(function() {  
console.log(testing);
});

More From » jquery

 Answers
8

if you add dinamically put the click on the list but select the items:



$(#results).on(click, .searchterm, function(event){
console.log('clicked');
});


try on the fiddle: http://jsfiddle.net/emPKS/


[#75342] Saturday, September 28, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
maxinec

Total Points: 117
Total Questions: 116
Total Answers: 116

Location: Bangladesh
Member since Sat, Jan 23, 2021
3 Years ago
maxinec questions
;