selection.classed()

selection.classed(names[, value])

If a value is specified, assigns or unassigns the specified CSS class names on the selected elements by setting the class attribute or modifying the classList property and returns this selection. The specified names is a string of space-separated class names. For example, to assign the classes foo and bar to the selected elements:

selection.classed("foo bar", true);

If the value is truthy, then all elements are assigned the specified classes; otherwise, the classes are unassigned. If the value is a function, then the function is evaluated for each selected element, in order, being passed the current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element. The function’s return value is then used to assign or unassign classes on each element. For example, to randomly associate the class foo with on average half the selected elements:

selection.classed("foo", function() { return Math.random() > 0.5; });

If a value is not specified, returns true if and only if the first (non-null) selected element has the specified classes. This is generally useful only if you know the selection contains exactly one element.

doc_D3_Js
2016-11-24 10:28:52
Comments
Leave a Comment

Please login to continue.