score:1
Selects all elements that match the specified selector string. The elements will be selected in document order (top-to-bottom). If no elements in the document match the selector, or if the selector is null or undefined, returns an empty selection. For example, to select all paragraphs:
var paragraph = d3.selectAll("p");
1) In your example, .legend
is a class selector. It is being passed as an argument to selectAll
to match all DOM elements that have a class of legend
.
2) .legend
is not a CSS style itself. But it can be used in CSS as a selector to apply some style properties to the elements that match said selector.
3) selectAll
accepts only one argument: a selector string. That could simply be "p"
or it could be ".content .items > li"
.
Have a look below how we can use both CSS & D3 to apply different styles.
d3.selectAll(".highlight")
.style({
"color": "green"
})
nav a {
color: red
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<nav>
<ul>
<li><a href="#nowhere" title="Lorum ipsum dolor sit amet">Lorem</a></li>
<li><a href="#nowhere" title="Aliquam tincidunt mauris eu risus">Aliquam</a></li>
<li><a href="#nowhere" title="Morbi in sem quis dui placerat ornare" class="highlight">Morbi</a></li>
<li><a href="#nowhere" title="Praesent dapibus, neque id cursus faucibus">Praesent</a></li>
<li><a href="#nowhere" title="Pellentesque fermentum dolor" class="highlight">Pellentesque</a></li>
</ul>
</nav>
Source: stackoverflow.com
Related Query
- Can selectAll() in d3 js take css style also as parameter?
- SVG: why does external css override inline style for text?
- Can you set style in d3 via something like foo.style({color:blah, background:blah})?
- SVG d3 | can I add inline style dynamically?
- How can I use D3.js to take an array of Javascript objects use them in a line graph?
- Adding css style when converting svg to png
- How to style using d3's .style() method instead of using CSS in style tags for .axis path {}?
- How can I style a tooltip for an NVD3 Chart?
- Defining CSS style for tooltip in d3.js body
- How can I change style class & content of text for ancestors in this d3.js tree?
- Setting axis' style without CSS
- Unable to Apply CSS style to SVG text element
- How do i select all nodes and apply a css style to all of them, D3
- When loading CSS with webpack, I can write CSS for tags, but not for classes or ids
- Can I use selectAll to create new element when elements of same type already exist?
- Responsive graphs: Get width and height of axis, so graph can take up remaining size of a container
- Can d3.js circle's radius be specified by a style attribute?
- Style d3 svg line with css
- How can a function with no parameters all of a sudden take parameters in javascript?
- axis text style in d3.js without CSS
- Why does my inline style not work CSS
- When I delete a rectangle how can I also delete its letter
- Transferring all CSS statements to D3 chains in JavaScript - trouble with hover style
- How to apply a CSS style sheet to a D3 force-directed graph?
- D3: How to assign style css to a specified id
- DC.js choropleth map chart CSS conflicting with colouring, no map showing. How can I turn off the fill:none?
- How can I use d3.js filter to assign different css classes to elements?
- how to use css to style if-else statement in d3
- How can I embed a graph from d3js with CSS
- style d3 axis with js rather than CSS
More Query from same tag
- Change object attribute following transition D3
- Drawing circles via d3js and converting coordinates
- How to split single line into multiple lines?
- Replacing JSON file with CSV for d3js
- Read csv to object of object for d3 [datamaps]
- dc.js legend is not displaying
- mouse over event on axis label d3.js javascript
- Uncaught SyntaxError: Unexpected end of JSON input
- How to invoke "click" event programmatically in d3?
- How to display d3 elements on a gridster box?
- Set a minimum height on bars in D3 graph
- d3 circlepacking how to not zoom out when clicking the same node twice
- Chart not rendering
- D3 reading promise data into a constructor
- How to enable static links for D3 charts
- How to layer D3 Force Simulation nodes based on element and not node order?
- D3: + operator before object call
- multiline chart in d3 with long format data
- Making a D3 Pie v4 Example - Animate On initial render
- return date value of Focus+Context via Brushing Chart
- Color descendant nodes and links broken after moving to d3 v5
- Replace space with new line charcter in texts d3js
- Can't get data from XML file
- D3 map tooltips
- How to clear the canvas without interrupting animations?
- D3 force directed graph issue: nodes are stacked at coordinate (0,0)
- Find if a coordinate point is within a topojson feature, geograpic area, using d3js
- Why is d3 pack layout crashing unexpectedly?
- Can't load image from SVG image element
- d3 multi-series chart zoom - pivoted json