Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing label class with checkbox selection

Status
Not open for further replies.

tinwe

Programmer
Feb 21, 2011
1
SE
Hi
I'm stuck.

I would really love some sort of javascript observer to automatically add/remove a class to the labels on my page, depending on wether their checkboxes are checked or not.

As well as adding those same CSS-classes to the labels, whose checkboxes are already checked on document load.
 
What have you tried so far?

The first step would be to get all the checkboxes, and access their className property and change it.

Code:
var mycheckbox=document.getElementById('mycheckboxID');
mycheckbox.className='newclassname';


If the checkboxes are named the same you can use getElementsByName to get a collection of the checkboxes with the same name and then loop through them to change their class.


With that said, you may n see any change as most browsers don't apply visual stylings to checkboxes.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top