English 中文(简体)
D3中的j Query s 美元(大米:第一)是多少?
原标题:What is the equivalent of jQuery s $(".cell:first") in D3?

我受审

d3.select(".cell:first")
d3.selectAll(".cell").filter(":first")
d3.selectAll(".cell").select(":first")

工作

最佳回答

<代码>d3.select(优等)已经选定了第一个对应要素:

选择与特定甄选者扼杀相对应的第一个要素,退回单一要素选择。 如果本文件中没有任何内容与特定的甄选者相匹配,则将空选取回。 如果多重因素与甄选者相匹配,将只选定第一个匹配要素(在文件处理中)。

资料来源:https://github.com/mbostock/d3/wiki/Selections#wiki-d3_select

"How would I get the last item?"

D3似乎将<代码>d3.selectAll()的成果退回到一个阵列中。 例如,请在d3 主页。 结果:

[ Array[32] ] // An array with a single array child. Child has 32 paragraphs.

因此,如果我们想从这一收集中得到最后一段,我们就可以做以下工作:

var paragraphs = d3.selectAll("p");
var lastParag  = paragraphs[0].pop();

更简明扼要:

var obj = d3.select( d3.selectAll("p")[0].pop() );

"What about :last-child?"

The :last-child selectedor isn t the same as 带上最后一页。 这名选择人将给你作为母集装箱最后一名子女的内容。 考虑以下标记:

<div id="foo">
  <p>Hello</p>
  <p>World</p>
  <div>English</div>
</div>
<div id="bar">
  <p>Oie</p>
  <p>Mundo</p>
  <div>Portuguese</div>
</div>

在这种例子中,d3.select(>p:last-child”>赢得了任何段落的回报。 甚至<代码>d3.selectAll(“p:last-child”)> 这些集装箱中没有一个是最后一段(即<div>s:<div>English</div><div>Portuguese</div>

问题回答

如果你想从D3的甄选中获取第一种OM要素,则使用<代码>.node()方法:

var sel = d3.selectAll( p ); // all <P>, wrapped with D3.selection
var el = sel.node(); // the first <P> element




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签