Assigning a whole style class with javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jebe@bee7.net

    #1

    Assigning a whole style class with javascript

    Hi all,

    I just struggling with the follwing problem: I have defined a style
    class
    ..myClass {
    color: ....
    font-weight: ...
    margin:...
    ...
    }

    and by using JavaScript I now want to assign the whole class to an HTML
    element (a table cell).
    The only topics I found were about how to assign a style attribute
    (like color:
    document.forms['myform'].elements[myElement].style.color = '#FF0000';
    )

    I have tried a lot but did not get the right syntax to assign my whole
    style class "myClass" instead of just the attribute.

    Isn't it possible or how is the correct syntax?

    Thanks in advance
    John

  • frizzle

    #2
    Re: Assigning a whole style class with javascript

    document.forms['myform'].elements[myElement].className = 'myClass';

    you're welcome ;)

    Comment

    Working...