socramm socramm - 1 year ago 47
HTML Question

html add class to item without ID with js

I want to add a class to a

using JavaScript, this is the html I have:

<li tabindex="-1" role="option" unselectable="on" class="k-item">
<input type="checkbox" name="categoryItems_option_1" value="1">&nbsp;
<label for="categoryItems_option_1" class="selctAllBox">Select/Deselect All</label>

I cant use the "k-item" class because there is more then one of them.

I added the "selectAllBox" class like that:


Is there a way to use something like parent or anything like that, to set the class?

Answer Source

You can use the parent, like so: