I can't find a browser-neutral way of modifying the text contained within a tag. Do I need to write a function to do it? Anyone got one? Or is there another way I've missed?
Announcement
Collapse
No announcement yet.
newbie. innerText vs. innerHTML vs. style.content
Collapse
X
-
innerHTML is the cross-browser way though not standard.
For DOM-compliant browsers, you can use DOM to create elements and text nodes on the fly.
For extensive lists of DOM references and other resources, see this sticky thread.
-
Thank you, once again a helpful answer. So here are some examples:Code:<HTML> <BODY onLoad="loader()"> <SCRIPT LANGUAGE="JavaScript"> <!-- Hide code from older browsers function loader() { pp = document.getElementsByTagName("P") pp[1].innerText = "Para 1 content dynamic " pp[2].style.content = "para 2 even more dynamic" pp[3].innerHTML = "yet another way" pp[4].childNodes[0].nodeValue = "which method is recommended?" } // End hiding--> </SCRIPT> <p> here's a para 0</p> <p> here's a para 1</p> <p> here's a para 2</p> <p> here's a para 3</p> <p> here's a para 4</p> <p id="five"> here's a para 5</p> </BODY> </HTML>
Comment
Comment