Permalink
Browse files

Remove sniffing from `Element` when detecting broken `setAttribute` i…

…n IE. [#571 state:resolved] (kangax)
  • Loading branch information...
savetheclocktower committed Mar 8, 2009
1 parent ba2c260 commit fa12b001117111ce393439d693f07325252a4747
Showing with 21 additions and 1 deletion.
  1. +2 −0 CHANGELOG
  2. +19 −1 src/dom/dom.js
@@ -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)
@@ -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);

0 comments on commit fa12b00

Please sign in to comment.