Reputation: 16632
I have a div tag and i'm changing its innerHtml attribute. And i want to add listener to this div tag to show/hide when its innerHtml changed.
Upvotes: 2
Views: 2120
Reputation: 342665
You can use setInterval
to check the contents periodically, and act accordingly, for example:
function innerHTMLChanged() {
if$("#myDiv").html() != "Some HTML for comparison, perhaps the previous state?") {
$("#myDiv").hide();
} else {
$("#myDiv").show();
}
}
// fires every half a second
setInterval(innerHTMLChanged, 500);
Upvotes: 1
Reputation: 8650
You wan't to use an onchange
feature. JavaScript does not yet have one built in. But there are plenty of code samples just a Google away for you to use.
Upvotes: -1
Reputation: 26227
There is no such thing as a "listener" for the innerHtml
attribute. What you would do (but shouldn't) is have a timer which checks if the value has changed since the last update. Please, don't do that.
Upvotes: 3