Fux*_*uxi 49 jquery class jquery-selectors
我正在尝试获得一个div,其中"panel current"作为classname.问题是空间 - 我该如何选择它?
cle*_*tus 117
类名不能包含空格.你有什么两个类:
<div class="panel current">
Run Code Online (Sandbox Code Playgroud)
这个div有两个类:panel和current.这很容易选择:
$("div.panel.current")...
Run Code Online (Sandbox Code Playgroud)
这意味着选择所有具有类面板和类当前的div .
Dav*_*ing 14
$('div').filter(function() {
return this.className == 'panel current';
});
Run Code Online (Sandbox Code Playgroud)
要么
$("div[class='panel current']");
Run Code Online (Sandbox Code Playgroud)
如果需要匹配具有完全匹配的类名(包括空格)的元素,请使用此选项
其他海报是对的,你发布的DiV有两个类名:'panel'和'current'; 如果要同时选择它们,请使用$('.panel.current').
这还包括以下元素:
<div class="foo panel bar current"></div>
Run Code Online (Sandbox Code Playgroud)
panel current不是类名,实际上它是两个类名.您可以使用以下选择器:
$('.panel.current')
Run Code Online (Sandbox Code Playgroud)