I''m working on a framework that builds off of the latest snapshot
prototype.js for use where I work. It contains parts that:
- Repeat a set of html code and inserts it as the innerHTML of an
element
- Adds a method to each element that will return child elements by id
I''ve found that in ie, after I alter the innerHTML, if I then use my
child by id routine to grab an element, and send it through $() to
have it "extended" the child element comes out the other end without
being extended.
It turns out that in some situations the _extended attribute ends up
on these children without it ever being placed there. Maybe because
after the repeating of the HTML, elements temporarily have the same id.
I found that if _extended is a function and not just a ''true''
flag
then ie won''t mysteriously place it on unextended elements.
For legacy reasons, I map $() to el() in my library. I''ve wrapped $
() with a fix that could easily be placed within $() itself.
// Same as $, but fixes ie bugs,
var el_extended = function() { return true; }
var el = function() {
var results = [], element;
for (var i = 0; i < arguments.length; i++) {
var elem = $(arguments[i]);
elem._extended = el_extended;
results.push(elem);
}
return results.length < 2 ? results[0] : results;
};
Hopefully this is useful to others and not redundant. I can provide
more details and work out a patch to prototype.js if needed. I''ve
not really dealt with subversion, etc, before, so it might be easier
if someone else could take this up.
I''d love to share more of what I''m doing re my framework, but
I need
to get some better clearance from those who can clear up all the
licensing specifics. I think that will happen, its just something
new to us. Prototype has been a great base to build from.
On 4/25/06, Joseph Annino <joe-Y2MrdnniGXJBDgjK7y7TUQ@public.gmane.org> wrote:> - Repeat a set of html code and inserts it as the innerHTML of an > element> Maybe because > after the repeating of the HTML, elements temporarily have the same id.Never insert something into the DOM that results in IDs not being unique. The browsers have to fall back into some recovery mode for this error, the behaviour with duplicate IDs is undefined, idiosyncratic and any hack is not future-proof. Avoid the situation. You seem to loop after the insertion to change the ID. Either change the IDs beforehand, or insert without IDs and set them on the loop. Bye, Martin
You are correct. However I''ve discovered when it comes to working with web browsers correct and practical are often different, especially as long as we have to support IE 6. I did try a dom based approach of cloning and inserting nodes to repeat them, setting the id before the insert, and it was slow and even more buggy under IE. I could use either dom techniques or regular expressions to ensure that all the ids are unique in the bits of innerHTML I am inserting. Again that would be slow (from what I''ve tried). So after I insert this less than ideal innerHTML with the duplicate ids, I find the new elements using childNodes, and make their ids unique. From all I have tried this has been the fastest approach. IE still sometimes puts the _extended attribute where it shouldn''t be, and changing its value to a dummy function seems to keep that from happening. I don''t run my nodes through $() until I have made their ids unique. Even using cloneNode and appendNode and changing the IDs beforehand (the academically correct way), I find ie often "entangles" nodes so that changing one affects an other, in a much worse way. So I am limited by IE into a less than perfect solution, however this solution does work in all the browsers prototype supports, including the IE7 beta. This simple change lets prototype keep working consistently for me even in such less than perfect situations, and I don''t really see any down side to it, if others are interested in using this small change. On Apr 25, 2006, at 3:46 AM, Martin Bialasinski wrote:> On 4/25/06, Joseph Annino <joe-Y2MrdnniGXJBDgjK7y7TUQ@public.gmane.org> wrote: > >> - Repeat a set of html code and inserts it as the innerHTML of an >> element > >> Maybe because >> after the repeating of the HTML, elements temporarily have the >> same id. > > Never insert something into the DOM that results in IDs not being > unique. The browsers have to fall back into some recovery mode for > this error, the behaviour with duplicate IDs is undefined, > idiosyncratic and any hack is not future-proof. Avoid the situation. > > You seem to loop after the insertion to change the ID. Either change > the IDs beforehand, or insert without IDs and set them on the loop. > > Bye, > Martin > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs