Closed Thread Icon

Topic awaiting preservation: DOM Element CSS Class Pages that link to <a href="https://ozoneasylum.com/backlink?for=24514" title="Pages that link to Topic awaiting preservation: DOM Element CSS Class" rel="nofollow" >Topic awaiting preservation: DOM Element CSS Class\

 
Author Thread
Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 12-28-2004 02:53

Hey guys;

With HTML, you can set CSS classes as follows: <div class="bar baz"></div>, when in the CSS, you have .bar and .baz defined. Now, what I have done is create a DOM element; I want to be able to set this attribute. Is there any way I can do it?

code:
var foo = document.createElement("div");

foo.class = "bar baz"; // This line is obviously invalid. I am looking for code that sets the CSS class here.

document.body.appendChild(foo);



Thanks.

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 12-28-2004 03:15

Ah, it's just a matter of finding the exact search terms you need in Google.

It turns out it's foo.className. I wasn't too far off. :X

Sorry for the clutter.

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

JKMabry
Maniac (V) Inmate

From: raht cheah
Insane since: Aug 2000

posted posted 12-28-2004 04:28

clutter no, info yes! thanks

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 12-28-2004 15:26

for the record, the correct ways ( I know of ) to set the class attribute of an element is :

code:
myElement.className = "the classes I want";
// or
myElement.setAttribute( "class", "the classes I want" );



Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 12-28-2004 16:08

now, for exercise, turn this into a faq.

« BackwardsOnwards »

Show Forum Drop Down Menu