It is required among the hundreds of tags "a" to find the required class with the selected class and add one more class to it.

if($('a').hasClass('selected')){ $(this).addClass('red'); } 
 .red{color: red;} 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a href="#" class="selected">One</a> 

Something is not right ...

  • 2
    Possible duplicate question: Lost call context - Grundy
  • @Grundy I did not find the answer to my question - Proshka
  • It is described as determined by what this is equal to. Look at what it is equal in your case - Grundy
  • one
    In general, you and the condition is not necessary. You want elements with the class selected add another class. First select the necessary elements, and then add a class to them: $('a.selected').addClass('red') - Grundy
  • When switching tabs, the class in the active window changes to selected. So I do not know how to approach, so that when switching tabs, the background color of the active tab changes - Proshka

0