문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top