Skip Navigation

[Resolved] Trying to add class to checkbox label when input is :checked

This support ticket is created 7 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Tagged: 

This topic contains 1 reply, has 1 voice.

Last updated by joshM-4 7 years, 5 months ago.

Author
Posts
#458806

I am trying to: use jQuery to add a class to checkbox labels when the checkbox input is in a state of :checked

I visited this URL:

I expected to see: the class added to the label

Instead, I got: the class added for a brief moment and then removed after the search content is updated

I'm using this jQuery to add a class to the parent label of checkbox inputs in the parametric checkboxes because the label is wrapping the input instead of being a sibling to it (inconvenient markup in my opinion). Anyway, the class gets added for a brief moment and then gets overwritten by something ( the search results are set to be updated when any value is updated ).

Here's the jQuery:

jQuery(document).on("change","input[type=checkbox]",function () {
    jQuery(this).parent().toggleClass("chked");
});

I'm not sure what I need to do. I'm trying to add the class so I can style the checkbox display instead of using the ugly default browser checkboxes. But for some reason it's not sticking.

Thanks in advance for your help.

#458807

I spent the last hour trying to get this to work and just figured it out after submitting the ticket.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.