setting style and class dynamically

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard Trahan

    setting style and class dynamically

    This code doesn't work:

    document.getEle mentById("myid" ).style.backgro undColor = "#abcdef"

    This should work in NN7.2 and IE6.0. What am I doing wrong?

    "myid" refers to <input type="text" id="myid">, which gladly obeys
    an internal style="backgrou nd-color: #abcdef".

    Also, I can't find any mention of a class property in the DOM; IOW,
    document.getEle mentById("myid" ).class always crashes, yet class works in
    the <input> tag. Is it not possible to dynamically change the class of
    an element?
  • Michael Winter

    #2
    Re: setting style and class dynamically

    On Sun, 19 Sep 2004 19:56:12 GMT, Richard Trahan <rtrahan@optonl ine.net>
    wrote:
    [color=blue]
    > This code doesn't work:
    >
    > document.getEle mentById("myid" ).style.backgro undColor = "#abcdef"[/color]

    When are you executing that code? If it's before the element, myid, has
    been parsed you should get an error stating that myid couldn't be found.
    If not, please show an example including HTML (preferably in a host web
    page).

    [snip]
    [color=blue]
    > Also, I can't find any mention of a class property in the DOM; IOW,
    > document.getEle mentById("myid" ).class always crashes, yet class works in
    > the <input> tag. Is it not possible to dynamically change the class of
    > an element?[/color]

    It is possible. You set the class using the className property. The DOM
    HTML Specification briefly mentions why this name change took place.

    Good luck,
    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.

    Comment

    Working...