By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,453 Members | 959 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,453 IT Pros & Developers. It's quick & easy.

setting style and class dynamically

P: n/a
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?
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Sun, 19 Sep 2004 19:56:12 GMT, Richard Trahan <rt*****@optonline.net>
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.
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.