From fa12b001117111ce393439d693f07325252a4747 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Sun, 8 Mar 2009 18:18:55 -0500 Subject: [PATCH] Remove sniffing from `Element` when detecting broken `setAttribute` in IE. [#571 state:resolved] (kangax) --- CHANGELOG | 2 ++ src/dom/dom.js | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index d1ebe36..be8280c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Remove sniffing from `Element` when detecting broken `setAttribute` in IE. [#571 state:resolved] (kangax) + * Remove sniffing from `Element.update` branching in favor of feature detection. [#574 state:resolved] (kangax) * Remove sniffing when branching `escapeHTML` and `unescapeHTML`. [#570 state:resolved] (kangax) diff --git a/src/dom/dom.js b/src/dom/dom.js index 679ad7d..1d58343 100644 --- a/src/dom/dom.js +++ b/src/dom/dom.js @@ -71,12 +71,30 @@ if (!Node.ELEMENT_NODE) { * Creates an HTML element with `tagName` as the tag name. **/ (function(global) { + + // setAttribute is broken in IE (particularly when setting name attribute) + // see: http://msdn.microsoft.com/en-us/library/ms536389.aspx + var SETATTRIBUTE_IGNORES_NAME = (function(){ + var elForm = document.createElement("form"); + var elInput = document.createElement("input"); + var root = document.documentElement; + elInput.setAttribute("name", "test"); + elForm.appendChild(elInput); + root.appendChild(elForm); + var isBuggy = elForm.elements + ? (typeof elForm.elements.test == "undefined") + : null; + root.removeChild(elForm); + elForm = elInput = null; + return isBuggy; + })(); + var element = global.Element; global.Element = function(tagName, attributes) { attributes = attributes || { }; tagName = tagName.toLowerCase(); var cache = Element.cache; - if (Prototype.Browser.IE && attributes.name) { + if (SETATTRIBUTE_IGNORES_NAME && attributes.name) { tagName = '<' + tagName + ' name="' + attributes.name + '">'; delete attributes.name; return Element.writeAttribute(document.createElement(tagName), attributes);