#507 ✓invalid
William Warby

References from document.createElement not extended in IE

Reported by William Warby | December 29th, 2008 @ 07:06 PM

I've just come across a weird problem - I'm not sure if this qualifies as a bug in Prototype or a bug in IE (or both):


var el = document.createElement('div');
el.id = 'foo';
$('container').appendChild(el);
alert('el->visible(): ' + el.visible); // <-- undefined
alert('foo->visible(): ' + $('foo').visible); // <-- function

Essentially, if you store a reference to an element created using document.createElement, the referenced object has none of the Prototype extended methods. This is specific to Internet Explorer - at least, it does not occur in Firefox. It's also specific to Prototype extended stuff - native properties get updated properly:


var el = document.createElement('div');
el.id = 'foo';
$('container').appendChild(el);
$('foo').innerHTML = 'bar'; // <-- update a native property after adding the element to the DOM
alert('el->innerHTML: ' + el.innerHTML); <-- 'bar'
alert('foo->innerHTML: ' + $('foo').innerHTML); <-- 'bar'

Make of this what you will. The solution is:


var el = document.createElement('div');
el.id = 'foo';
$('container').appendChild(el);
el = $('foo');
alert('el->visible(): ' + el.visible); // <-- function
alert('foo->visible(): ' + $('foo').visible); // <-- function

...but should I really have to do this hack?

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket

Pages