hi,
i have a unordered list of links, which are dynamically created by Ajax, and for each link i want to add click function to it, but it won't work, please help!
here is my code:
HTML:
<div id="sidebar">
<li>
<h2> list </h2>
<ul id="list"></ul>
</li>
</div>
JS:
//to create links
var str = '';
$.each(json.opts, function(i, opt) {
var id = opt + '-list';
str += '<li><a href="#" id='+ id +'>' + opt + '</a></li>'; //link
}
$("#list").html(str);
...
//to add click function to each links, this won't work
$("#list li").each(function (i) {
alert(i + " : " + $(this).text());
});