forked from cytoscape/cytoscape.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Element toggleclass
maxkfranz edited this page Nov 28, 2011
·
2 revisions
Toggle whether an element has a class.
- classNames : A space-separated list of class names to toggle
- classNames : A space-separated list of class names to toggle
- toggle : If true, adds the class; if false, removes the class
Without the toggle argument specified, the class is automatically toggled based on whether the element already has the classes specified. For each class specified, if the element has the class, the class is removed. Otherwise the class is added.
var n1 = cy.node("n1");
n1.addClass("foo");
n1.removeClass("bar");
n1.toggleClass("foo"); // n1 has neither foo nor bar
n1.toggleClass("bar"); // bar added
n1.toggleClass("bar", true); // add bar, but bar is already there; no effect
n1.toggleClass("bar", false); // removed bar