I need to make some JQuery execute when the page/document has changed - in this case, when a div with a specific CSS class is displayed.
I have the following JQuery code:
<script>
$(document).change(function () {
if ($('.validation_errors').length) {
alert("test");
}
}
</script>
However, it does not execute and display the alert. Am I missing something here?
Change is only for input, textarea or select elements. Instead you need to bind a function to the DOMSubtreeModified
mutation event:
$(document).bind('DOMSubtreeModified', function () {
if ($('.validation_errors').length) {
alert("test");
}
});
EDIT: If your target browsers support it, you should use a MutationObserver instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With