Detect element content changes with jQuery

后端 未结 15 2258
余生分开走
余生分开走 2020-11-22 04:19

change() function works and detects changes on form elements, but is there a way of detecting when a DOM element\'s content was changed?

This does not w

15条回答
  •  礼貌的吻别
    2020-11-22 05:21

    The browser will not fire the onchange event for

    elements.

    I think the reasoning behind this is that these elements won't change unless modified by javascript. If you are already having to modify the element yourself (rather than the user doing it), then you can just call the appropriate accompanying code at the same time that you modify the element, like so:

     $("#content").html('something').each(function() { });
    

    You could also manually fire an event like this:

     $("#content").html('something').change();
    

    If neither of these solutions work for your situation, could you please give more information on what you are specifically trying to accomplish?

提交回复
热议问题