There are 2 blocks. In the first block there are several radio with a unique value, in the second there are several inline-block with display: none. It is necessary that when choosing radio, the inactive-block blocks add the class .active, if they have the same value in id as the value of radio

<div> <input type="radio" value="1"> </div> <div> <div class="one" id="1">test1</div> <div class="one" id="1">test2</div> <div class="one" id="2">test3</div> </div> <script> var MyValue = $("input:radio:checked").val(); $(".block").filter("#MyValue").addClass("active"); </script> 

I try to solve the problem in this way - it does not work. The value value is written to MyValue, checked. But it is impossible to substitute it in filter (). If instead of #MyValue I write for example "# 1", then it works as I need - elements with id = "1" are displayed

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

To solve, you need to collect a string substituting the value of a variable, not its name.

 $('#'+MyValue).addClass("active"); 
  • Thanks for the help, it helped! - Alexander