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.
+1
A:
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.
Deniz Dogan
2010-04-26 10:35:38
A:
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.
thecoshman
2010-04-26 10:35:50
A:
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);
karim79
2010-04-26 10:37:14
Would someone care to explain the down-vote?
karim79
2010-05-08 17:44:21