Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>d3.select(".cell")</code> already selects the first matched element:</p> <blockquote> <p>Selects the first element that matches the specified selector string, returning a single-element selection. If no elements in the current document match the specified selector, returns the empty selection. If multiple elements match the selector, only the first matching element (in document traversal order) will be selected.</p> </blockquote> <p>Source: <a href="https://github.com/mbostock/d3/wiki/Selections#wiki-d3_select" rel="nofollow noreferrer">https://github.com/mbostock/d3/wiki/Selections#wiki-d3_select</a></p> <h3><em>"How would I get the last item?</em>"</h3> <p>D3 appears to return the results of <code>d3.selectAll()</code> in a collection, positioned in an array. For instance, requesting all paragraphs on the <a href="http://d3js.org/" rel="nofollow noreferrer">d3 homepage</a> results in:</p> <pre class="lang-js prettyprint-override"><code>[ Array[32] ] // An array with a single array child. Child has 32 paragraphs. </code></pre> <p>So if we wanted to get the last paragraph from that collection, we could do the following:</p> <pre class="lang-js prettyprint-override"><code>var paragraphs = d3.selectAll("p"); var lastParag = paragraphs[0].pop(); </code></pre> <p>Or more concisely:</p> <pre class="lang-js prettyprint-override"><code>var obj = d3.select( d3.selectAll("p")[0].pop() ); </code></pre> <h3><em>"What about :last-child?"</em></h3> <p>The <code>:last-child</code> selector isn't the same as getting the last element on a page. This selector will give you the elements that are the last child of their parent container. Consider the following markup:</p> <pre class="lang-html prettyprint-override"><code>&lt;div id="foo"&gt; &lt;p&gt;Hello&lt;/p&gt; &lt;p&gt;World&lt;/p&gt; &lt;div&gt;English&lt;/div&gt; &lt;/div&gt; &lt;div id="bar"&gt; &lt;p&gt;Oie&lt;/p&gt; &lt;p&gt;Mundo&lt;/p&gt; &lt;div&gt;Portuguese&lt;/div&gt; &lt;/div&gt; </code></pre> <p>In this example, running <code>d3.select("p:last-child")</code> won't return any of your paragraphs. Even <code>d3.selectAll("p:last-child")</code> won't. Neither of those containers have a last child that is a paragraph (they are <code>&lt;div&gt;</code> elements: <code>&lt;div&gt;English&lt;/div&gt;</code> and <code>&lt;div&gt;Portuguese&lt;/div&gt;</code>). </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload