Text

Oct 28, 2010
@ 12:14 pm
Permalink
2 notes

Non-Input onChange events

Here’s something useful.

A scenario I stumbled upon, was about firing an event in the similar manner that the onChange event does for web form inputs, but for any other element in the DOM. Some google-fu later I discovered the DOMAttrModified event, which does just that.

Except that it doesn’t work in IE. I thought that it was a bit too easy. IE does its stuff in its own propertychange event. On top of that, you probably want to prevent the default event from ever firing.

var
    selector = $('.magnets'),
    event = $.browser.msie ? 'propertychange' : 'DOMAttrModified';

selelector.bind(event, function (e) {
    // Do whatever you want, man.

    if ($.browser.msie) e.preventDefault();
});
  1. piparkaq posted this