1

I have a question about DOMAttrModified. Which changes to an HTML Element properties triggers the DOMAttrModified event (specifically interested in Firefox, but an answer that applies to other browsers might suffice too)?

I have the following test case :

        var elem = document.createElement('input');
        document.body.appendChild(elem);

        elem.id    = 'inputId';      // triggers DOMAttrModified
        elem.type  = 'text';         // triggers DOMAttrModified
        elem.value = 'inputValue';   // DOES NOT trigger DOMAttrModified
        elem.lang  = 'en';           // triggers DOMAttrModified

If I change elem.value to elem.defaultValue, then a DOMAttrModified does get triggered. Is there a comprehensive list somewhere? So far I have found HTMLInputElement's 'value' and 'checked' and HTMLOptionElement's 'selected' property not trigerring DOMAttrModified. Are there any other?

The answer at DOMAttrModified visual attributes does NOT seem to be completely correct, as 'value' is also an attribute.

Thanks, Sunil

Community
  • 1
  • 1
Sunil Agrawal
  • 679
  • 4
  • 14

2 Answers2

3

Please also note that NO DOMAttrModified events will be fired when the 'disabled' attribute is set. So if your event is not firing, that could be the reason. This also goes for the IE-only 'onPropertyChange' event.

jenming
  • 809
  • 7
  • 8
  • 1
    Is that true even for the Mutation Observers, i.e. they aren't included in the mutation records? If yes, that would be a bummer. – Sunil Agrawal Nov 29 '12 at 01:37
3

The DOM value property doesn't change the HTML value markup attribute. The DOM defaultValue does. DOMAttrModified fires when markup attributes change, so on setAttribute/removeAttribute calls and on any property set that changes an attribute.

Boris Zbarsky
  • 34,758
  • 5
  • 52
  • 55
  • Thanks for the response. But my question is, is there a comprehensive list of such 'special attributes' and other 'property' that don't actually cause DOMAttrModified. So far I have found INPUT element's 'value' and 'checked', OPTION element's 'selected'. And then there are properties like 'scrollLeft' and 'scrollTop' that don't cause DOMAttrModified (understandably). – Sunil Agrawal Mar 31 '12 at 16:13
  • @SunilAgrawal Sure. Look in the HTML spec at the definitions of all the properties. The ones that don't say they reflect a content attribute don't have anything to do with content attributes. There's no precooked list of those, of course. And anything not defined in the HTML spec wouldn't reflect content attributes, obviously. – Boris Zbarsky Mar 31 '12 at 20:41
  • Just for my sake, can you please give me some examples (other than the ones I mentioned above). Just want to make sure I understand the answer :). – Sunil Agrawal Apr 01 '12 at 22:32
  • Start at http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#elements-in-the-dom and look at the property names; the ones that don't say they reflect content attribute don't reflect content attributes (e.g. 'accessKey', 'commandType', and the various on* properties). And then there are some that might reflect different attributes depending on the element (e.g. 'itemValue') – Boris Zbarsky Apr 02 '12 at 00:32