views:

62

answers:

3

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
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
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
Would someone care to explain the down-vote?
karim79