I am a newbie at JavaScript.
I want to add a class to my <label>
tag, which has no class at first. The reason why I want this is to create CSS rules to the <label>
when being active, so I also want to remove the class when I click on other <label>
.
<div class="radio">
<label data-label="" for="fld_8583385_1_opt1271141"><input type="radio" id="fld_8583385_1_opt1271141" data-field="fld_8583385" class="fld_8583385_1" name="fld_8583385" value="15" checked="checked" data-radio-field="fld_8583385_1" data-type="radio" data-calc-value="15">
Some Text</label>
</div>
<div class="radio">
<label data-label="" for="fld_8583385_1_opt1611303"><input type="radio" id="fld_8583385_1_opt1611303" data-field="fld_8583385" class="fld_8583385_1" name="fld_8583385" value="10" data-radio-field="fld_8583385_1" data-type="radio" data-calc-value="10">
Some Text</label>
</div>
Here is my JavaScript that doesn't seem to work:
document.getElementsByTagName("LABEL").onclick = function(){
document.getElementsByTagName("LABEL").addClass("test");
}