Don't confound the element with its reference. Even after you have appended an element, you may set new attributes on it using its reference. The only thing you should keep in mind is that a new created element can be appended only once.
Note: You have chosen, unfortunately, a wrong example. DIV elements can not bear a name, they can only have an id.
Don't confound the element with its reference. Even after you have appended an element, you may set new attributes on it using its reference. The only thing you should keep in mind is that a new created element can be appended only once.
Reference? What does getElementsByTagName return? A list of references?
Also, my dynamically created pages contain a huge number of div elements, which makes getElementsByTagName slow down the application. (especially with IE).
So I decided to save my own array of elems (Nodes) and update newly created elements there.
In other words, each time I need to add/remove an element, I insert/remove child from the page, and then add/remove cells from the saved list of elems.
The thing is, while the add works great (probably because of the reference) the remove with removeChild() doesn't... Any idea?
Why not? from what I can see, all browsers support it.
If by all the browsers you mean IE ... No, definitely no. All the browsers, except IE, will return undefined the following:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
onload=function(){
var div=document.getElementsByTagName('div')[0];
alert(div.name);
}
</script>
</head>
<body>
<div name="myDiv"></div>
</body>
</html>
IE is famous for another mismatch: If id is not defined, IE will take the name as id, or the id as name if the name is missing. Completely wrong, according to the standards.
name is to be used only for the form's controls. It may be used for links, images and frames/iframes as well, but the W3C Recommendation is to use the name only for the form's controls.
Bookmarks