These are some readers' responses. Read the full article to see what all the fuss is about.
-
Popular
Categories
- .Net & C# (1)
- C++ (5)
- Coding (3)
- Copyright, etc. (3)
- HTML/CSS (2)
- Java (14)
- JavaScript (5)
- JUnit (3)
- Recommendations (9)
- Risks (6)
- Software projects (2)
- SQL (4)
- Testing (6)
- Tools (4)
- Web (4)
- Web publishing (16)
- Windows (1)
- WordPress (27)
35 responses
Other comment pages: [1] 2 »
Here’s Simon Willison’s
createElement()function.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!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.
I have no problems setting the class of an element. Use this:
element.className = 'someClass';This works in IE6, at least.
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
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;
}
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.
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.
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, 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.
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
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.
Other comment pages: [1] 2 »