Daaah Daaah - 1 year ago 77
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_ k').toggleClass("active");


Do not work.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download