[英]How do I select only nodes with a certain CSS class ? D3/JS
我只想選擇應用了“隱藏”類的節點。 我還有其他應用了“隱藏”類的形狀,但是我只需要選擇節點。
我認為這可能有效:
var nodesVisible = inner.selectAll(".node").selectAll(".hidden")
.classed("hidden", false);
在HTML中,它具有: class: "node hidden"
所以我也嘗試過
var nodesVisible = inner.selectAll("node hidden")
但這不會選擇應用了隱藏類的節點
有任何想法嗎 ?
類需要加一個點:
var nodesVisible = inner.selectAll(".node.hidden")
選擇所有使用CSS選擇器。 這是有關CSS選擇器的文檔: http : //www.w3schools.com/cssref/css_selectors.asp
您只能使用這樣的純JavaScript來做到這一點
的HTML
<div id="c" class="hidden otherclass"> </div>
JAVASCRIPT
var div=c //get the element by id
if(div.className.indexOf('hidden')>-1&&
div.className.indexOf('otherclass')>-1){
alert("yes the element has a hidden and otherclass classes")
// do other stuff
}
更新
我在條件中添加了> -1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.