Methods
addClass(className) → {selection}
jQuery equivalent: $.addClass
Adds class to elements in the current selection. Returns current selection.
Parameters:
Name | Type | Description |
---|---|---|
className |
string |
The class to insert |
- Source:
Example
d3.selectAll('ul').addClass('active');
d3.selectAll('ul').addClass('class-a class-b'); //will add two classes
after(tagName) → {selection}
jQuery equivalent: $.after
Inserts new elements after each element in the current selection. Returns the newly created elements as a d3 selection.
Parameters:
Name | Type | Description |
---|---|---|
tagName |
string |
The element to insert |
Example
d3.selectAll('li')
.after('li')
.text('Item');
//do something else with the inserted elements...
appendTo(tagName) → {selection}
jQuery equivalent: $.appendTo
Appends elements of the current selection to the target element. Returns the target selection.
Parameters:
Name | Type | Description |
---|---|---|
tagName |
string |
The element to append |
- Source:
before(tagName) → {selection}
jQuery equivalent: $.before
Inserts new elements before each element in the current selection. Returns the newly created elements as a d3 selection.
Parameters:
Name | Type | Description |
---|---|---|
tagName |
string |
The element to insert |
Example
d3.selectAll('li')
.before('li')
.text('Item');
//do something else with the inserted elements...
clear() → {selection}
jQuery equivalent: $.empty
Removes all children of the current selection. Returns the current selection. We are using another name for this function as in jQuery, because d3 already has an empty function.
css() → {selection}
jQuery equivalent: $.css
Applies style to elements in the current selection. Returns the selection. Works in the same way like the D3 style function we only changed the name here.
eq(index, groupIndexopt) → {element}
jQuery equivalent: $.eq
Reduces current selection to the element with the passed index. Returns element. If you have a nested group, you can also specify the group index, to select a certain group.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
index |
string |
The index to select |
|
groupIndex |
string |
<optional> |
Group to select |
first() → {selection}
jQuery equivalent: $.first
Reduces the current selection to the first element. Then returns the reduced selection.
hasClass(className) → {bool}
jQuery equivalent: $.hasClass
Checks if current selection has the passed class. Returns true or false.
Parameters:
Name | Type | Description |
---|---|---|
className |
string |
The element to append |
- Source:
hide() → {selection}
jQuery equivalent: $.hide
Hides the current selection. Returns the selection.
last() → {selection}
jQuery equivalent: $.last
Reduces the current selection to the last element. Then returns the reduced selection.
moveToBack()
Displays SVG element above the other ones.
- Source:
moveToFront()
Displays SVG element below the other ones.
- Source:
on(types, listener, capture) → {selection}
jQuery equivalent: $.on
Works like the normal on
function but now you can pass multiple event types like you know it from jquery.
We took this function from the awesome d3-jetpack
Parameters:
Name | Type | Description |
---|---|---|
types |
string |
- |
listener |
string |
- |
capture |
string |
- |
prepend(tagName) → {selection}
jQuery equivalent: $.prepend
Inserts elements as first child of the current selection. Returns the new elements as a D3 selection.
Parameters:
Name | Type | Description |
---|---|---|
tagName |
string |
The element to append |
- Source:
removeClass(className) → {selection}
jQuery equivalent: $.removeClass
Removes class from elements in the current selection. Returns current selection.
Parameters:
Name | Type | Description |
---|---|---|
className |
string |
The class to remove |
- Source:
Example
d3.selectAll('ul').removeClass('active');
d3.selectAll('ul').removeClass('class-a class-b'); //will remove two classes
show() → {selection}
jQuery equivalent: $.show
Diplays the current selection. Returns the selection.
toggle() → {selection}
jQuery equivalent: $.toggle
Diplays or hides the current selection. Returns the selection.
toggleClass(className) → {selection}
jQuery equivalent: $.toggleClass
Adds or removes class from elements in the current selection. Returns current selection.
Parameters:
Name | Type | Description |
---|---|---|
className |
string |
The css class to toggle |
- Source: