I hope this title says what I want to do. I have a checkbox on my site. I want to check variable and then add class='checked'
to above element. For example:
<div class="checker" id="uniform-personalData1"><span><input name="personalData1" id="personalData1" value="0" type="checkbox"></span></div>
If js variable like say $a = 1
I want to add class='checked'
to <span>
. Like this:
<div class="checker" id="uniform-personalData1"><span class="checked"><input name="personalData1" id="personalData1" value="0" type="checkbox"></span></div>
How can I do this thing by using jquery ?
Kind regards
Hi @adam It's quite simple. Just use addClass method of jQuery. Like below.
var $a = 1;
if ($a === 1) {
$('#uniform-personalData1 > span').addClass('checked');
console.log($('#uniform-personalData1 span'));
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments