var.innerHTML where var is a variable!!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Keiron Waites

    var.innerHTML where var is a variable!!

    Is there any way to use a variable.innerH TML = ""; instead of text.innerHTML
    = "";? It doesn't seem to work for me.

    Thanks,

    Keiron


  • Lasse Reichstein Nielsen

    #2
    Re: var.innerHTML where var is a variable!!

    "Keiron Waites" <webmaster@-NOSPAM-sharemonkey.com > writes:
    [color=blue]
    > Is there any way to use a variable.innerH TML = ""; instead of text.innerHTML
    > = "";? It doesn't seem to work for me.[/color]

    I am sorry, but I can't see what you are trying to do.

    The "innerHTML" property is a property of Document Object Model nodes,
    not of text strings. You can do
    document.getEle mentById("elemN ame").innerHTM L = "<em>foo</em>";
    and you can do
    var variable = document.getEle mentById("elemN ame");
    variable.innerH TML = "<em>foo</em>";
    but you can't write
    "text string".innerHT ML = "<em>foo</em>";

    I am afraid you will ahve to be a little more explicit about what you
    are trying to do, if we are to be able to help you.

    (and as a side note, you can't have a variable called "var". That is
    a reserved word in Javascript.)

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Martin Honnen

      #3
      Re: var.innerHTML where var is a variable!!



      Keiron Waites wrote:[color=blue]
      > Is there any way to use a variable.innerH TML = ""; instead of text.innerHTML
      > = "";? It doesn't seem to work for me.[/color]

      Use
      var element;
      if (document.all) {
      element = document.all[variable];
      }
      else if (document.getEl ementById) {
      element = document.getEle mentById(variab le);
      }
      if (element) {
      element.innerHT ML = ...
      }



      --

      Martin Honnen


      Comment

      Working...