how to access dynamically created list in jquery?

Posted by Ohana on Stack Overflow See other posts from Stack Overflow or by Ohana
Published on 2010-03-18T00:18:40Z Indexed on 2010/03/18 0:21 UTC
Read the original article Hit count: 612

Filed under:

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:

  • list

  • //to create links var str = ''; $.each(json.opts, function(i, opt) { var id = opt + '-list'; str += '

  • ' + opt + '
  • '; //link } $("#list").html(str);

    ... //to add click function to each links, this won't work $("#list li").each(function (i) { alert(i + " : " + $(this).text()); });

    © Stack Overflow or respective owner

    Related posts about jQuery