There are actually selectors like this:

#checkbox1:checked + .checkbox-label 

How to select them with jquery? This type of code does not work:

 $('#checkbox1:checked + .checkbox-label').css({ // здесь провожу манипуляции с css }) 
  • And why, in fact, do it, if you can describe all styles in css? - Cheg
  • one
    And by the way, your code is working. It is just necessary to use it at every manipulation with checkboxes - Cheg

1 answer 1

Your code is a working example by reference jsfiddle

May not work due to the fact that no matching item was found. In order to understand why the corresponding part of HTML is not working.

I will explain on #checkbox1:checked + .checkbox-label . This is a selector (“prev + next”). It searches for the element "next", which is after the element "prev" within the common "parent".

Those. if we place prev and next in different blocks, the code will not work.

  • I just need to change the styles of this block at a certain moment - Swartex
  • For example, I created two events: when the button is clicked and when the checkbox status changes. See an example - Petr Kulikov
  • in thanks! I get it now :) - Swartex