0

I know I have already asked this question here . But since I dint find the solution there. I am re-posting the same question. Kindly bear with me.

Please find the fiddle here.

HTML:

<label>
<input type="checkbox" id="" class="checkbox" name="Hello"><span>Hello</span>
</label>

CSS:

label {
display: block;
width: 85%;
font: normal 12px/1.6em Arial;
}
.correctPadding .checkbox {
margin: 0;
display: inline;
margin-right: 6px;
margin-top:2px;
}
input[type="checkbox"]:checked + span {
font-weight: bold;
}

My JS trial is:

if ($('.checkbox').is(':checked')) {
    $(this).next().css({ "font-weight": "bold" })
}

The check box label should get bold, when a check box is checked. It is working in all browsers, except for IE8.

Can we solve this please

Community
  • 1
  • 1
Archana
  • 253
  • 7
  • 25

2 Answers2

0

maybe so

$(document).ready(function(){
   $('input[type="checkbox"]').each(function(){
    if(/span/i.test($(this).next()[0].tagName) && this.name){
     $(this).change(function(){
      $('input[type="checkbox"][name="'+this.name+'"]').each(function(){
       $(this).next()[this.checked?"addClass":"removeClass"]("Checked");
      });
     });
     if(this.checked) $(this).next().addClass("Checked");
    }
   })
  }); 
label {
    display: block;
    width: 85%;
    font: normal 12px/1.6em Arial;
}
.correctPadding .checkbox {
    margin: 0;
    display: inline;
    margin-right: 6px;
    margin-top:2px;
}
input[type="checkbox"]:checked + span {
    font-weight: bold;
}
.Checked{
 font-weight: bold;
 color: #f00; /*for example*/
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<label>
    <input type="checkbox" id="" class="checkbox" name="Hello"><span>Hello</span>
</label>
    <label>
    <input type="checkbox" id="" class="checkbox" name="Hello"><span>Hello 2</span>
</label>
        <label>
    <input type="checkbox" id="" class="checkbox" name="Hello"><span>Hello 3</span>
</label>
            <label>
    <input type="checkbox" id="" class="checkbox" name="Hello"><span>Hello 4</span>
</label>
Dmitriy
  • 4,475
  • 3
  • 29
  • 37
0

This is as simple as this:

$(".checkbox").change(function () {
    if ($(this).next().hasClass("checkboxSpanTextBold")) {
        $(this).next().removeClass("checkboxSpanTextBold");
    }
    else {
        $(this).next().addClass("checkboxSpanTextBold");
    }
});

CSS:

.checkboxSpanTextBold {
font-weight:bold;
}

Using change will do things for me.

Thanks everyone for your supporting.

Archana
  • 253
  • 7
  • 25