Why is onpropertychange not working for me?

I am in IE 9 and I call:

document.attachEvent('onpropertychange', function(){
    console.log("triggered");
});

in the console which returns true.

Then I change an attribute:

$('div').eq(0).attr("data-url", "url");

which changes the attribute but does not print triggered to the console. What am I doing wrong?

Answers


According to MSDN, this event does not bubble, so placing the handler on the document wouldn't observe property changes on div elements.

Also, I'm not certain that a change to a sub property of element.dataset would trigger the hander. Worth testing I suppose.


Perhaps you should try attaching this event to all of your divs like this:

var divs = $('div');
$.each(divs, function(divObj){
 divObj.attachEvent('onpropertychange', function(){
  console.log("triggered");
 });
});

Need Your Help

Mobile website, portrait to landscape

html5 css3 mobile-website

I'm making a mobile website, in portrait the nav bar is sized nicely with 15px of padding around the top and bottom, but when I switch to landscape mode, it takes up almost half the screen.