0

How do I check whether checkbox is checked and background color needs to be changed using jquery or javascript.

<div class="index" id="test">
    <h2>testing</h2>
       <div class="string">
         <ul>
            <li class="nv1">
               <input type="checkbox" value="in1" id="chk1" />
                <div class="checkbox-select">lblstr1</div>
                <div class="checkbox-deselect">lblstr2</div>
            </li>
         </ul>
      </div>
 </div>

CSS for this...

.string li.nv1,
.nv1 .checkbox-select {
 width: 120px;

 }

.nv1 .checkbox-deselect {
  width: 120px;
   background: #8dc63f;
 }

Thanks, ShailShin

Hushme
  • 3,108
  • 1
  • 20
  • 26
ShailShin
  • 69
  • 3

1 Answers1

2

Use

   if($("#chk1").is(":checked")){
         $(".checkbox-deselect").css("background" , "red");
   }
   else{
        $(".checkbox-deselect").css("background" , "green");
   }
Sudharsan S
  • 15,336
  • 3
  • 31
  • 49
  • hi, thanks a lot!, Is there a way to do the switch...case for given html code if multiple list present. Thanks, ShailShin – ShailShin Jul 23 '14 at 10:00