It's supported by almost all modern browsers now.
???
Right, that's it, thank you. The validators look at the HTML, not at the javascript.
===
Arie.
Printable View
Now what to do in a situation in which the only thing that works in a specific browser is innerHTML?
Here's an illustration of what I mean. If you want to dynamically create a text/htm-object, you can do the following in all browsers but IE:But for IE, the only way to accomplish this is:Code:function create_external(the_id,url,object_style)
{
var inserted=document.getElementById(the_id);
}
while (inserted.firstChild) {inserted.removeChild(inserted.firstChild);}
OBJ = document.createElement("object");
OBJ.setAttribute('type','text/html');
OBJ.setAttribute('data',url);
OBJ.setAttribute('style',object_style);
inserted.appendChild(OBJ);
}
Usage: something like:
href="#" onclick="create_external('some_id','bla.html', 'position:relative; width:190px; height:250px; background-color:yellow; left:0px; border:1px solid red;margin-top:9px'); return false; "
In this situation, shouldn't we use innerHTML for the IE-case? (The only alternative is that we don't do it for IE).Code:inserted.innerHTML='<object type="text/html" data="' + url + '", style="'+ object_style +'"><\/object>'
(Attribute assignment doesn't work for IE in this particular case).
See this thread for an illustration.
===
Arie.
Of course, legacy methods can and should be used as fallback for legacy browsers, should one choose to support them. You fall foul of 3.2, though, and additionally have failed to provide support for non-JS browsers, which would also be an acceptable fallback for IE.
setAttribute() and getAttribute() are never necessary in JS when dealing with HTML, and IE has some issues with them. They are used for programming languages which are incapable of looking up properties by a string name, and also for XML.
nice.
...They are simply called as what the functions says. "Attributes". It's pointless in JS because you also have this:Code:setAttribute() and getAttribute() are never necessary in JS when dealing with HTML, and IE has some issues with them. They are used for programming languages which are incapable of looking up properties by a string name, and also for XML.
For calling attributes as strings.Code:array["someItem"]
Best darned tips I've ever seen!!
-magicyte