Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > setting style and class dynamically

Reply
Thread Tools

setting style and class dynamically

 
 
Richard Trahan
Guest
Posts: n/a
 
      09-19-2004
This code doesn't work:

document.getElementById("myid").style.backgroundCo lor = "#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="background-color: #abcdef".

Also, I can't find any mention of a class property in the DOM; IOW,
document.getElementById("myid").class always crashes, yet class works in
the <input> tag. Is it not possible to dynamically change the class of
an element?
 
Reply With Quote
 
 
 
 
Michael Winter
Guest
Posts: n/a
 
      09-19-2004
On Sun, 19 Sep 2004 19:56:12 GMT, Richard Trahan <(E-Mail Removed)>
wrote:

> This code doesn't work:
>
> document.getElementById("myid").style.backgroundCo lor = "#abcdef"


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]

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


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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
new-style class or old-style class? Jayden Python 9 09-27-2012 12:30 AM
Dynamically setting a MasterPage's <body> tag style Mark Rae ASP .Net 12 07-12-2006 03:40 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
Need help with Style conversion from Style object to Style key/value collection. Ken Varn ASP .Net Building Controls 0 04-26-2004 07:06 PM
New style class & Old style class in Python dlo_olb Python 2 06-25-2003 01:46 PM



Advertisments