chadmichael Posted May 1, 2006 Share Posted May 1, 2006 I want to change the text of an html element when a javascript function is called. Let's say my initial html contains<div id="title"> <b>Little house on the Priarie</b> </div>How do I progammatically change the text of this to someother title? Thanks Link to comment Share on other sites More sharing options...
scott100 Posted May 1, 2006 Share Posted May 1, 2006 Use innerHTML: http://www.w3schools.com/dhtml/tryit.asp?f...e=trydhtml_demohttp://www.w3schools.com/dhtml/tryit.asp?f...l_dom_innertext Link to comment Share on other sites More sharing options...
chadmichael Posted May 1, 2006 Author Share Posted May 1, 2006 I thought innerHTML was deprecated. Is it still the prefferred and best supported method for dynamically changing text? Link to comment Share on other sites More sharing options...
Webworldx Posted May 1, 2006 Share Posted May 1, 2006 It's not part of the W3C DOM, but i'd say it's the best supported and yes the most preferred way of text change.We chatted about innerHTML and the alternative W3C here: http://w3schools.invisionzone.com/index.ph...indpost&p=20049 Link to comment Share on other sites More sharing options...
raimo Posted May 2, 2006 Share Posted May 2, 2006 It's not part of the W3C DOM, but i'd say it's the best supported and yes the most preferred way of text change.<{POST_SNAPBACK}> I think it depends of what we need to get changed, only value of one text node or array of html tags.innerHTML is very good if there is many tags or should I say nodes. But if only need is change text value of one element DOM is not bad at all.innerHTML:document.getElementById('id').innerHTML = 'gerbils are not rats!'; DOM: document.getElementById('id').firstChild.nodeValue = 'me tarzan you jane?'; OK, with DOM firstChild must exists, innerHTML wrotes is there nodes inside of element or not,but that is not a big problem, I think. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now