When trying to attach a getter/setter to a native DOM property on an element, the getter/setter seems to be ignored and is never called. The original behavior is maintained. Use this simple code testcase: <div id="d"></div> <script type="text/javascript"> var o=document.getElementById("d"); o.__defineSetter__("id",function () { alert("SET"); }); o.id="test"; </script> Expected behavior: an alert saying "SET". Actual behavior: nothing. The same code works as expected in Firefox and Chrome. Similarly, attaching the getter/setter on the prototype (for example, on HTMLDivElement.prototype) fails on Safari and Chrome as well, but works as expected in Firefox.
It's worth noting that this testcase also works as expected in Opera, and the same functionality can be achieved in IE8 using their getter/setter syntax: Object.defineProperty(o, "id", { set: function () { alert("SET"); } }); /* or */ Object.defineProperty(HTMLDivElement.prototype, "id", { set: function () { alert("SET"); } });
Created attachment 30941 [details] test case Same test, as an attachment.
*** This bug has been marked as a duplicate of 12721 ***