What a difference a space makes

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">
  </div>
</div>
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">
</div>
then the selector looks the same, but without a space between the classes
$('.red.blue')
This won't work if one of the classes is represented by a variable. In that case, do this:
$('.red.'+var)

Tags

Add new comment

Markdown

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>
  • Missing filter. All text is removed
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.