Selection in D3.js

Array of DOM elements with special D3 methods.

For more information see https://github.com/mbostock/d3/wiki/Selections.

Inherits from:

Instance Properties

name type description
constructor Object A reference to the constructor class for the current object instance. [from Object]
length Number The number of items in the array. [from Array]
prototype Object The prototype for a class. [from Object]

Instance Methods

name returns description
append(tagName) Selection Create and append new elements, returning a new selection of them.
attr(name,value) Selection Set attribute to a value.
attr(name) Selection Get attribute value.
attr(name,func) Selection Set attribute value from data.
call() Element Find the first DOM element in the selection.
call(func,[arg1],[arg2],…) Selection Invoke a function, passing the selection and returning it.
classed(name,setFlag) Selection Add/remove a CSS class from the selection.
classed(name,func) Selection Add/remove a CSS class from the selection based on data.
classed(name) Boolean Check to see if the selection has the specified class.
concat([item1],[item2],[...]) Array Concatenates one or more items or arrays onto the current array. [from Array]
data() Array Get the data array for the first group in the selection.
data(dataValues,[keyCalculator]) Selection Set the data array for the selection, computing the update, enter, and exit selections.
data(dataCalculator,[keyCalculator]) Selection Set the data array for the selection based on existing data.
datum() Object Return the data associated with the first element in the selection (if any).
datum(value) Selection Set the data associated with elements in the selection.
datum(func) Selection Set the data associated with elements in the selection based on existing data.
each(func) Selection Call a function for each element in the selection.
empty() Boolean Test if there are any DOM elements in the selection.
enter() EnterSelection Return the array of placeholders for ‘missing’ elements associated with data.
exit() Selection Return the selection of elements no longer associated with data.
hasOwnProperty(propertyOrMethodName) Boolean Determines if the object/instance itself has the named property or method. [from Object]
html() String Get the innerHTML for a DOM element.
html(func) Selection Set the HTML content for elements in the selection based on data.
html(newHTML) Selection Set the HTML content for elements in the selection.
insert(tagName,beforeSelector) String Create and insert new elements before existing ones, returning a selection of the new elements.
isPrototypeOf(instanceToTest) Boolean Determines if the calling object prototype is in the inheritance chain for the supplied argument. [from Object]
join([separator]) String Returns a string representation of the array, separated by the delimiter of your choice. [from Array]
on(eventName,eventHandler,capturePhase) Selection Retrieve the event listener for an event type.
on(eventName) Selection Retrieve the event listener for an event type.
order() Selection Reorder the elements in the DOM to match the order of elements in the selection.
pop() Object Remove the last element from the array and return it. [from Array]
property(name) String Get the value of a DOM property.
property(name,value,[priority]) Selection Set a DOM property for elements in the selection.
property(name,func) Selection Set a DOM property for elements in the selection based on data.
propertyIsEnumerable(propertyOrMethodName) Boolean Determines if the object/instance itself has a property or method of the supplied name which will appear in a for (prop in obj) enumeration. [from Object]
push([item1],[item2],[...]) Number Adds one or more elements to the end of the array, returning the new length. [from Array]
remove() Selection Remove all elements in the selection from the document; returns the selection.
reverse() Array Reverses the order of the elements in the array, and returns the array. [from Array]
select(selector) Selection Find the first descendant elements of the selection matching a selector.
select(selectCalculator) Selection Use a function to select a different element for each entry in the selection.
selectAll(selector) Selection Select multiple elements for each entry in the selection.
selectAll(selectCalculator) Selection Use a function to select multiple elements for each entry in the selection.
shift() Object Removes the first element of the array and returns it. [from Array]
slice(start,[end]) Array Return a specified section of an array. [from Array]
sort([compareFunction]) Array Sort the array. [from Array]
sort(comparator) Selection Sort the order of elements in the selection (and DOM) according to custom criteria.
splice(start,deleteCount,[newItem1],…) Array Remove a section from the array and return it; optionally inserting new values in that place. [from Array]
style(name) String Get the computed value of a CSS style property.
style(name,func,[priority]) Selection Set a CSS style property for elements in the selection based on data.
style(name,value,[priority]) Selection Set a CSS style property for elements in the selection.
text(newText) Selection Set the text content for elements in the selection.
text() String Get the textContent for a DOM element.
text(func) Selection Set the text content for elements in the selection based on data.
toLocaleString() String For most objects, the same as toString() unless explicitly overridden. [from Object]
toString() String Returns a string representation of the object. [from Object]
transition() Transition Start a new Transition for the selection.
unshift([newItem1],[newItem2],[...]) Number Insert items to the front of an array, and return the new length. [from Array]
valueOf() String Returns the internal this value of the object. [from Object]

Methods that return a Selection

name of object description
append(tagName) EnterSelection Create and append new elements for all the placeholder entries, returning a new selection of the created elements.
append(tagName) Selection Create and append new elements, returning a new selection of them.
attr(name,value) Selection Set attribute to a value.
attr(name) Selection Get attribute value.
attr(name,func) Selection Set attribute value from data.
call(func,[arg1],[arg2],…) Selection Invoke a function, passing the selection and returning it.
classed(name,setFlag) Selection Add/remove a CSS class from the selection.
classed(name,func) Selection Add/remove a CSS class from the selection based on data.
data(dataValues,[keyCalculator]) Selection Set the data array for the selection, computing the update, enter, and exit selections.
data(dataCalculator,[keyCalculator]) Selection Set the data array for the selection based on existing data.
datum(value) Selection Set the data associated with elements in the selection.
datum(func) Selection Set the data associated with elements in the selection based on existing data.
each(func) Selection Call a function for each element in the selection.
exit() Selection Return the selection of elements no longer associated with data.
html(func) Selection Set the HTML content for elements in the selection based on data.
html(newHTML) Selection Set the HTML content for elements in the selection.
on(eventName) Selection Retrieve the event listener for an event type.
on(eventName,eventHandler,capturePhase) Selection Retrieve the event listener for an event type.
order() Selection Reorder the elements in the DOM to match the order of elements in the selection.
property(name,func) Selection Set a DOM property for elements in the selection based on data.
property(name,value,[priority]) Selection Set a DOM property for elements in the selection.
remove() Selection Remove all elements in the selection from the document; returns the selection.
select(selectCalculator) Selection Use a function to select a different element for each entry in the selection.
select(selector) Selection Find the first descendant elements of the selection matching a selector.
select(selector) d3 Select an element from the current document.
select(node) d3 Select an element from the current document.
selectAll(selectCalculator) Selection Use a function to select multiple elements for each entry in the selection.
selectAll(nodes) d3 Select multiple elements from the current document.
selectAll(selector) d3 Select multiple elements from the current document.
selectAll(selector) Selection Select multiple elements for each entry in the selection.
sort(comparator) Selection Sort the order of elements in the selection (and DOM) according to custom criteria.
style(name,func,[priority]) Selection Set a CSS style property for elements in the selection based on data.
style(name,value,[priority]) Selection Set a CSS style property for elements in the selection.
text(newText) Selection Set the text content for elements in the selection.
text(func) Selection Set the text content for elements in the selection based on data.

Arguments that are a Selection

name in method of object description
selection transition(selection) d3