I'm trying to get a div which has "panel current" as classname. The problem is the space - how can I select it?
A space in a CSS selector has very special meaning. It means that the part of the selector that occurs right of the space is within (a child of) the part of the selector to the left. This doesn't apply to your second example, because it has no space.
The class name can't contain a space, but it can contain hyphens or underscores. Any tag can have multiple space-separated class names.
Use the getElementsByClassName method to get elements by multiple class names, e.g. document. getElementsByClassName('box green') . The method returns an array-like object containing all the elements that have all of the given class names.
The . The jQuery . class selector finds elements with a specific class.
Class names can't have spaces in them. What you have there is two classes:
<div class="panel current">
This div has two classes: panel and current. That's easily selected:
$("div.panel.current")...
That means select all divs that have class panel and class current.
$('div').filter(function() { return this.className == 'panel current'; });
OR
$("div[class='panel current']");
Use this if you need to match an element with an exact match of class names (including spaces)
The other posters are right, the DiV you posted has two class names: 'panel' and 'current'; If you want to select them both, use $('.panel.current')
.
This will also include elements like:
<div class="foo panel bar current"></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With