How can I call a function after an element has been created in jquery?

前端 未结 9 2269
野趣味
野趣味 2020-12-28 13:37

I want to call a function after an element has been created. Is there a way to do this?

Example:

$(\"#myElement\").ready(function() {
    // call the         


        
9条回答
  •  长发绾君心
    2020-12-28 14:18

    You may want to look into jQuery live events. You attach an event handler to a selector that either matches now or after additional elements are created in your DOM.

    So if you have a

      and you dynamically create new
    • items, in your $(document).ready() you can wire up a selector to an event handler so that all of your
    • elements will be wired for that event.

      Here's a jsFiddle sample that demos live.

      Hope this helps.

提交回复
热议问题