[Javascript] Changing an Objects ID and Name

Paul Novitski paul at juniperwebcraft.com
Wed Sep 6 16:34:00 CDT 2006


At 9/6/2006 11:34 AM, John Warner wrote:
>Paul, let me show my ignorance, but can you 'swap' id attributes in the
>fashion below? What I mean is you would seem to have for a moment two
>elements with the same ID. The parser 'should' get rather upset with
>this situation. Of course I know there is something I'm not seeing here.


Good call.  Although I've seen the DOM tolerate elements with 
duplicate ids, you're right that we shouldn't rely on it in deference 
to future engines that are more strict.  Perhaps a better way would be:

         sId1 = oObj1.id;
         sId2 = oObj2.id;

         oObj1.id = '';
         oObj2.id = sId1;
         oObj1.id = sId2;

Paul 




More information about the Javascript mailing list