I have many divs in a page, like so:
<div class="formitem food-6 group-7">
//content of div
<input type="checkbox"> //child of div
</div>
<div class="formitem food-7 group-7">
//content of div
<input type="checkbox"> //child of div
</div>
When a checkbox is checked, I want to store the value of it's parent's unique class e.g "food-6" or "food-7" in a variable. I can get all the classes of the parent, like this:
parent = $(this).closest(".formitem").attr("class");
Which gives me formitem food-7 group-7.
How can I get "the one that starts with food-" ?
food-7class for computation instead of CSS, have you considered usingdata-attributes instead?