I am learning jQuery. If I have the following html code on my page:
<div class="transport car">
<button type="button" class="car" >car</button>
</div>
I have the following two questions:
-
In jQuery, what does selector
$('.transport.car')refers to? the whole div or the button?? -
Is
$('.transport[name]')refers to the element with class ‘transport’ and MUST have name attribute?
The
div. It selects an element that has both, thetransportand thecarclass. To select the button, you would have to add a space:$('.transport .car'). Now it is the descendant selector.Yes. But the attribute can be empty.
The selector syntax is basically the same as the one of CSS. jQuery just adds some custom selectors.
Btw. you can easily test this yourself.