How to do an action when an element is added to a page using Jquery?

后端 未结 1 817
感情败类
感情败类 2020-12-05 11:38

When I add something of the class \"myClass\" I want to call a function on this element.

It would be something in the lines of:

jQuery(\".error_messa         


        
相关标签:
1条回答
  • 2020-12-05 12:20

    The short, direct answer to your question would be "no can do." But from your comment a few minutes ago, I see that you want to add elements in different ways and have one unified method of handling these newly added items. May I suggest another approach? Trigger custom events.

    The way it would work is like this: everywhere you load the error-message element, you add one line when it's done:

     $('.error_message').trigger('load');
    

    Now your .live('load'...) thing will work.

    0 讨论(0)
提交回复
热议问题