我有一个由 d3.js 生成的 svg,如下所示:
<svg height="1094" width="1254">
<g id="countries" stroke-width="1px" transform="">
<path d="M100,519.150,200,250" fill="rgba(100,100,100,0.8)"
stroke="rgba(200,200,200,0.5)" id="id1" class="1"></path>
<path d="M100,519.150,200,250" fill="rgba(100,100,100,0.8)"
stroke="rgba(200,200,200,0.5)" id="id2" class="1"></path>
<path d="M100,519.150,200,250" fill="rgba(100,100,100,0.8)"
stroke="rgba(200,200,200,0.5)" id="id3" class="3"></path>
<path d="M100,519.150,200,250" fill="rgba(100,100,100,0.8)"
stroke="rgba(200,200,200,0.5)" id="id4" class="1"></path>
</g>
</svg>
我想做这样的事情:
foreach(path in #countries){
if(this.class === 3){dostuff}
}
我试过jquery方式:
$('#countries').find('path').each(function( index ) {
console.log(this);
});
... 不记录任何内容
我尝试了 d3.js 方式(国家初始化如下:)countries = svg.append('svg:g').attr('id', 'countries')
:
countries.select('path').each(console.log(this));
countries.selectAll('path').each(console.log(this));
记录窗口对象(wtf?)