-1

I need a jQuery event that trigger when any change on structure of the element happen:

<div id="example"></div>

trigger when:

<div id="example" ></div>
<!-- OR -->
<div id="example" another-attr=""></div>
<!-- OR -->
<div id="example2"></div>
<!-- OR -->
<div id="example"> </div>

Basically, I need a trigger for any change. Is there one?

4
  • 2
    you need to make mutationObserver, or use mutation events developer.mozilla.org/en-US/docs/Web/API/MutationObserver developer.mozilla.org/en-US/docs/Web/Guide/Events/… Mar 29, 2016 at 19:29
  • Would it be possible to edit the event that manipulates the DOM and affects these elements and add your additional actions to that action instead? Or is there another action you know happens that changes these sections that you could then do a check of these elements and trigger your action that way? (like an on.blur() then check if $("#example").prop('another-attr') matches a condition?) Mar 29, 2016 at 20:05
  • I wish to bind any change on that element, doesnt metter from where it comes. Even the user forcing a change or a jQuery manipulation... Mar 29, 2016 at 20:07
  • User forcing changes, i mean: Opening the console and editing the element. Mar 29, 2016 at 20:07

2 Answers 2

1

Since you're asking about JQuery, I ran into a similar challenge and found the answer here in another question:

jQuery: How to listen for DOM changes?

I hope this helps!

1
  • i mean, at the mentioned question, the right answer doesnt work for me.. i'm not sure if thats a functionality especific from mozzila firefox... i'll work on it Mar 29, 2016 at 20:01
0

You can create a trigger that captures when HTML content has changed.

I have done so in the following codpen link.

Basically in this example you click a button that changes the content of the p tag, thus triggering the content change. To prove that the content change was captured successfully an alert is shown. You will have to put the following code after the changes you want to capture:

$('html').trigger('contentchanged'); 

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.