Daaah Daaah - 5 months ago 16
jQuery Question

jQuery on each click of parent change child only

Fiddle here: https://jsfiddle.net/0b4etshr/1/

How can I make the text of on each

item_ k
change color ( toggleClass() ) when the input is checked?

$('item_').each(function(){
$(".iOScb").click(function(){
$('item_ k').toggleClass("active");

});
});


Do not work.

Answer

You can do something like this:

$("item_ [type='checkbox']").change(function() {
  $("k", $(this).parents("item_")).toggleClass("active");
});

Basically, any time a checkbox contained in the <item_> tag changes its state, the k tag contained in <item_> but in an level upper than the checkbox toggles the active class.

Comments