I'm trying to write a click
function to select the next g.slice
node, add a class of .sliceActive
to it and remove .sliceActive
from the original .slice
. However, only when you are at the last g.slice
(with a class of .slice5
) you would add the .sliceActive
to the the first g.slice
with a class of .slice0
.
This is what I have so far that is not working. I think the problem is I don't know how to see if the current .sliceActive
node also has the class of .slice5
.
$(".next").click(function(){
var nextSlice;
if(d3.select("g.sliceActive").hasClass("slice5")){
nextSlice= d3.select(".slice0");
}else{
nextSlice= d3.select("g.sliceActive + g");
}
d3.select("g.sliceActive").classed("sliceActive",false);
nextSlice.classed("sliceActive",true);
});
And here is how it looks in the web inspector:
d3's classed
function with no second parameter will return whether the selected element has the passed class.
d3.select("g.sliceActive").classed("slice5")
Should tell you what you need to know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With