mSyx mSyx - 22 days ago 7
CSS Question

Check if X = Y, if yes, aplly CSS on Z div

Before all, I did try to search for a solution on both Google and Stackoverflow, but nothing helped /or i'm a bad searcher/.

It's quite simple but i'm not qualified nor good enough to do it by myself.
I'm looking for a way (jQuery or not) to check if X = Y, and if it is the case, then apply a specific class on Z.

Any idea ?
Thanks !

Answer

It is very simple my friend (use jQuery), you should try it out:

var A = 1;
var B = 1;
if(A == B) { // Matching the conditions (if they are equal)
  // If they are equal, then add a class using jQuery's addClass Method!
  $('.Z').addClass('myClass');
}
.myClass{
  color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!---- HTML Code ----->
<div class="A">A</div>
<div class="B">B</div>
<div class="Z">Z</div>

The jQuery's addClass() method adds the specified class(es) to each element in the set of matched elements.

Hope this helps!