Setting the “name” attribute in Internet Explorer

These are some readers' responses. Read the full article to see what all the fuss is about.

35 responses

Other comment pages: [1] 2 »

  • Mathias Bynens | 17 June 2005
  • Simon’s createElement() function could indeed be useful for some users. (It solves an IE6 problem when creating elements in XML documents.) It still doesn’t allow you to create named elements, but you could combine the two functions to solve both problems at once!

    Bennett | 27 June 2005
  • I found that the same problem applies to the class attribute of an element. So possibly even more attributes can’t be set with the W3C setAttribute method.

    daco | 9 August 2005
  • I have no problems setting the class of an element. Use this:

    element.className = 'someClass';

    This works in IE6, at least.

    Bennett | 10 August 2005
  • [...] After about another hour or two of fruitless Google-ing, I finally typed in the magic phrase (setting the name attribute in Internet Explorer) a[...]
  • Trackback | tag-strategia.com » IE DOM Bugs | 8 February 2006
    [...] Bennett McElwee suggested a solution in his blog that is nicely cross-browser; anything other than IE throws an exception and gets created prope[...]
  • The createElement function seems not to work properly in Opera 8.51 (tested on Windows XP SP2). It won’t throw an error with the IE way and instead, selectEl.nodeName will gives you back the whole string you used as the argument for document.createElement. This problem seems to be solved in the Opera 9 technology preview.

    To make it work with Opera

    Kristof Coomans | 17 February 2006
  • My previous reply seems to have been stripped.

    So, to make it work with Opera 8.51, you can do this:
    if (!element || element.nodeName != type.toUpperCase())
    {
    element = document.createElement( type );
    element.name = name;
    }

    Kristof Coomans | 17 February 2006
  • Thanks, Kristof. I had long been meaning to test this on other browsers, and you spurred me into action. I have incorporated your change, and the function now works in Opera 8.5 and Netscape 7.1. I appreciate the time you took to share your discoveries.

    Bennett | 17 February 2006
  • Newer versions of opera browser will try to create element with try and catch method, and they will also managed to do it, so try and catch method is not useful for opera, because it can not properly set up attributes for element, so the created elements actually doesn’t have atributes previously set up with IE create Element method, but the element itself does exist. FF behave normally. So for Opera you will have to find out it’s really opera if (window.opera) object detection method, that is really effecive way to find out it’s opera and you will have to addapt your script also for opera.

    FantomX1 | 6 April 2006
  • Trackback | alt-tag.com » IE DOM Bugs | 19 June 2006
    [...] Bennett McElwee suggested a solution in his blog that is nicely cross-browser; anything other than IE throws an exception and gets created prope[...]
  • if (!element || element.nodeName != type.toUpperCase())
    {
    element = document.createElement( type );
    element.name = name;
    }

    This is a problem with IE/Mac as element.nodeName returns the whole string used in the argument for document.createElement and type.toUpperCase() returns the element type.

    Annette | 5 July 2006
  • Annette, it sounds as if Mac IE is thoroughly broken. I didn’t think Mac IE was still supported these days — what version of IE do you refer to? One day I’ll fire up my ancient PowerBook (Mac OS 9) and give it a try.

    Bennett | 8 July 2006
  • tag-strategia.com ยป IE DOM Bugs,
    It’s recommended to avoid the use of innerHTML because it does not adjust to the W3 standards, also I’ve found some cases where it does not works properly.
    There are some cases where it seems that the code is not parsed when innerHTML is used.
    The name issue discused here is due to a bad DOM implementation from Microsoft (oh my god! how can this be possible! lol).
    Read this page also:
    http://www.easy-reader.net/archives/2005/09/02/death-to-bad-dom-implementations/

    Ernesto Spiro Peimbert Andreakis | 26 October 2006
  • @Ernesto

    Yeah, the other problem with .innerHTML is that IE will not register any inline events you set properly, worse yet, you can’t create any DOM event handlers either.

    steve | 2 December 2006

Other comment pages: [1] 2 »

Post your comment | RSS feed for comments
Close
E-mail It