JQuery access dynamically created objects

后端 未结 3 1868
梦如初夏
梦如初夏 2021-01-28 05:41

How can I acceess objects(divs) that were dynamically generated. I mean DIVS that were not present in output when $(document).ready(function() started.

If I

3条回答
  •  面向向阳花
    2021-01-28 06:22

    Just put the click binding inside the first click function:

    $('#click_me').click(function() 
    {
        $('#container').append('
    can you click on me?
    '); $('#clicker2').click(function(){ alert('hurray, it works'); }); });

    As you have it, the binding is being called, but there is no "div#clicker2" to bind to the second function.

    Hope this helps.

提交回复
热议问题