I am trying to add strikethrough when i select a checkbox in my form (Bootstrap v3). I coded this bootply:
<div class="form-group ">
<label for="inputName" class="col-md-1 control-label">select</label>
<div class="col-md-5">
<div class="checkbox">
<label><input type="checkbox" name="packersOff" class="strikethrough" value="1">sssssssss</label>
</div>
</div>
</div>
and added a class in css
.strikethrough:checked{
text-decoration:line-through;
}
but it doesn't work..
Problem is that you are trying to apply
line-through
on checkbox where as the text is inside the label. You can wrap the text inside a<span>
and alter it's CSS on:checked
Bootply
jQuery solution:
Here is a solution to put a strike through when your input is checked:
HTML:
CSS
JSFIDDLE
With this solution when ever the checkbox is checked it will do something to the label. so you could make it bold or change its colour if you wanted.
This worked for me.
Source: https://developer.mozilla.org/en-US/docs/Web/CSS/%3Achecked
In order to make it work, rearrange your HTML to:
And your CSS to:
DEMO.