...

View Full Version : object.innerHTML substitute



looka
05-29-2006, 06:36 AM
is innerHTML html valid?
what can be other chance to insert in a specific element group of elements?

thanks

danbopes
05-29-2006, 06:48 AM
you have to use the


var newElement = document.createElement('ELEMENT');

and then do


obj.parentNode.appendChild(newElement);

Kor
05-30-2006, 08:53 AM
there are more methods to create elements and attributes and to append elements. The main are:

document.createElement('tagname'); //to create tagged elements
document.createTextNode('sometext');//to create text

root.appendChild(newElement);//to append an element to a root (parent)
root.insertBefore(newElement,someChild);// to insert an element in a specific place

newElement.setAttribute('attribute','value');// to set an attribute
newElement.style.someCSSattribute='value'; // to set a CSS attribute
newElement.className='someclass'; // to set a class
newElement.onevent=function(){somefunction(param)}// to attach an event

GJay
05-30-2006, 10:57 PM
is it worth mentioning that although .innerHTML might not be valid, it's present in all the main browsers,probably isn't going away any time soon and is often easier to use?

SantosJ
06-06-2006, 07:58 PM
is it worth mentioning that although .innerHTML might not be valid, it's present in all the main browsers,probably isn't going away any time soon and is often easier to use?
Easier perhaps, but I find that DOM is a lot more fun to play with.

Kor
06-06-2006, 08:55 PM
is it worth mentioning that although .innerHTML might not be valid, it's present in all the main browsers,probably isn't going away any time soon and is often easier to use?
innerHTML it is a good weapon, use it carefully, but if you try to use it and later try to access the DOM tree, u might have some problems (AJAX users knows what I mean)

A1ien51
06-07-2006, 10:28 AM
If you want to have fun, compare render times with Firefox and IE on DOM methods verus innerHTML. Firefox may surprise you.

Eric

Kor
06-07-2006, 10:36 AM
yes, I know, innerHTML is faster. This is why sometimes is good to be used, it depends on whether the DOM tree is to be called later or not.

A1ien51
06-07-2006, 10:41 AM
I personally use DOM methods and deal with IE's quirks!

Kor
06-07-2006, 10:43 AM
so do I. I guess that I use innerHTML only to check/debug the code :D

looka
06-12-2006, 11:53 AM
so, generally, innerHTML is, when not calling DOM structure ( i know, the inserted elements does not show there), the easiest way.

so i will stick in a innerHTML for now.

only one more thing - how can i insert <script> ? innerHTML does not eval it:(

anything else? document.write? those .createElement and .insertText methods?

otaku149
06-12-2006, 02:02 PM
how can i insert <script>

You can use createElement:


function loadJS(file){
if(document.createElement){
var el = document.createElement('script');
el.setAttribute('src', file);
document.documentElement.appendChild(el);
}
}

felgall
06-12-2006, 10:07 PM
innerHTML is supported by all the major browsers and was added to the W3C standards a few months ago. It is therefore entirely valid to use it, you just have to be aware that it works slightly differently from the DOM and so may not give the expected results depending on what it is you are trying to do.

Kravvitz
06-12-2006, 11:53 PM
felgall, could you show us a link for that?

brothercake
06-13-2006, 08:10 PM
innerHTML it is a good weapon, use it carefully, but if you try to use it and later try to access the DOM tree, u might have some problems (AJAX users knows what I mean)
What problems are those?

afaik you will get a DOM tree from an innerHTML operation, as long as the page is served as text/html.

felgall
06-13-2006, 10:05 PM
felgall, could you show us a link for that?

Maybe I made a mistake in believing what i was told from usually reliable sources as I am unable to locate the reference myself.

jkd
06-13-2006, 10:23 PM
Maybe I made a mistake in believing what i was told from usually reliable sources as I am unable to locate the reference myself.

DOM3 Load and Save has equivalent methods.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum