Web Analytics Made Easy -
StatCounter newbie. innerText vs. innerHTML vs. style.content - CodingForum


No announcement yet.

newbie. innerText vs. innerHTML vs. style.content

  • Filter
  • Time
  • Show
Clear All
new posts

  • newbie. innerText vs. innerHTML vs. style.content

    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?

  • #2
    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.
    vBulletin Mods That Rock!


    • #3
      Thank you, once again a helpful answer. So here are some examples:
      <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-->
      <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>
      running IE5 the style.content doesn't work (as advertised) but the others do; any overall recommendations or comments for a newbie? Should I use the DOM method for long-term reliability, for instance?