uzay95
uzay95

Reputation: 16632

adding listener to div tag to watching innerHtml content

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

Answers (3)

karim79
karim79

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

thecoshman
thecoshman

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

Deniz Dogan
Deniz Dogan

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

Related Questions