The problem you're having, is that you are using a Group Selector
, whereas you should be using a Multiples selector
! To be more specific, you're using $('.a, .b')
whereas you should be using $('.a.b')
.
For more information, see the overview of the different ways to combine selectors here belowherebelow!
##Group Selector : ","
Select all <h1>
elements AND all <p>
elements AND all <a>
elements :
$('h1, p, a')
##Multiples selector : "" (no character)
Select all <input>
elements of type
text
, with classes code
and red
:
$('input[type="text"].code.red')
##Descendant Selector : " " (space)
Select all <i>
elements inside <p>
elements:
$('p i')
##Child Selector : ">"
Select all <ul>
elements that are immediate children of a <li>
element:
$('li > ul')
##Adjacent Sibling Selector : "+"
Select all <a>
elements that are placed immediately after <h2>
elements:
$('h2 + a')
##General Sibling Selector : "~"
Select all <span>
elements that are siblings of <div>
elements:
$('div ~ span')