What a difference a space makes

18 June, 2024

Sometimes you need your selector to look for two classes...but what do you do when both classes are for the same element?

In normal circumstances, you might be looking to select class=red and class=blue

<div class="red">
  <div class="blue">

and would use the selector

$('.red .blue')

However, if you need to select the element that has both red and blue as its classes

<div class="red blue">

then the selector looks the same, but without a space between the classes


This won't work if one of the classes is represented by a variable. In that case, do this:



Login or Register to Comment!