faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

9 of 31 people (29%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

how to change the (stylesheet)class of an tag (eg <p class="cl1"> -> <p class="cl2">)?

Apr 7th, 2008 22:34
ha mo, Dave Clark, Matt Chatterley, david koenig,


First, retrieve the element e.g:

ob = getElementByID('Elem1');

Then update the style.class property:

ob.style.class = 'cl2';

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

     Hmmm...  "class" is not a style -- it is an HTML tag attribute.  
Seems that would have to be like this for cross-browser functionality:

ob = document.getElementByID('Elem1');
ob.className = 'cl2';

Take care,

Dave Clark
www.DaveClarkConsulting.com

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com