Skip to content

Commit aeb4532

Browse files
Fix odd behavior with new Element('select') in IE6-7. [#480 state:resolved] (Bruce Harris, kangax, Andrew Dupont)
1 parent 1fcf2e0 commit aeb4532

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Fix odd behavior with `new Element('select')` in IE6-7. [#480 state:resolved] (Bruce Harris, kangax, Andrew Dupont)
2+
13
* Extend BUTTON elements with everything defined in Form.Element.Methods. Ensure BUTTON elements are traversed in Form.getElements and serialized in Form.serialize. (Luis Gomez, Samuel Lebeau, kangax, Andrew Dupont)
24

35
* Ensure Object.isFunction returns `false` for RegExp objects. [#661 state:resolved] (James, kangax, Andrew Dupont)

src/dom/dom.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,18 @@ if (!Node.ELEMENT_NODE) {
154154
* var a = new Element('a', {'class': 'foo', href: '/foo.html'}).update("Next page");
155155
**/
156156

157-
(function(global) {
157+
(function(global) {
158+
// For performance reasons, we create new elements by cloning a "blank"
159+
// version of a given element. But sometimes this causes problems. Skip
160+
// the cache if:
161+
// (a) We're creating a SELECT element (troublesome in IE6);
162+
// (b) We're setting the `type` attribute on an INPUT element
163+
// (troublesome in IE9).
164+
function shouldUseCache(tagName, attributes) {
165+
if (tagName === 'select') return false;
166+
if ('type' in attributes) return false;
167+
return true;
168+
}
158169

159170
var HAS_EXTENDED_CREATE_ELEMENT_SYNTAX = (function(){
160171
try {
@@ -181,10 +192,8 @@ if (!Node.ELEMENT_NODE) {
181192

182193
if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName));
183194

184-
// Don't use the cache if we're setting the `type` attribute, as on an
185-
// INPUT element. This prevents an issue with IE9 beta.
186-
var node = ('type' in attributes) ? document.createElement(tagName) :
187-
cache[tagName].cloneNode(false);
195+
var node = shouldUseCache(tagName, attributes) ?
196+
cache[tagName].cloneNode(false) : document.createElement(tagName);
188197

189198
return Element.writeAttribute(node, attributes);
190199
};

0 commit comments

Comments
 (0)