M
M
MisTFoR2021-07-09 22:03:32
JavaScript
MisTFoR, 2021-07-09 22:03:32

How to do it so that the action works in the opposite direction?

Hello.
I have code:

$('.pr_water').click(function(){
  if($(this).attr('val')=='off'){
    $(this).attr('val', 'on');
  }
});

When the button is clicked, val="off" changes to val="on". I added 1 more code:<button class="pr_water" val="off">Кнопка</button>
$('.pr_water').click(function(){
  if($(this).attr('val')=='on'){
    $(this).attr('val', 'off');
  }
});

It is absolutely the same, only when val="on" is pressed, it would change to val="off", but this does not happen, what could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2021-07-09
@MisTFoR

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question