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.
Last edited by molendijk; 08-26-2008 at 10:40 PM. Reason: Correction
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.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
nice.
Please don't mind me. I am just posting a lot of nonsense.
...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"]
Last edited by mburt; 08-29-2008 at 01:51 AM.
- Mike
Bookmarks