NewToJS
NewToJS

Reputation: 2101

D3 select sibling, give it a class

I have several group elements, all are siblings.

I'm trying to select the one with the class of 'sliceActive' and give it a class of 'slice' and give the next sibling down the class of 'sliceActive'

enter image description here

all of this will be on the click event for my next button. I know how to select the .activeSlice and give it .slice but how to I select the next g node and give it .sliceActive?

       $(".button").click(function(){
            d3.select("g.sliceActive").attr('class','slice');
        });

Upvotes: 2

Views: 3176

Answers (1)

Stephen Thomas
Stephen Thomas

Reputation: 14053

You can use CSS adjacent sibling

d3.select("g.sliceActive + g").attr('class','sliceActive');

Might want to check browser support based on your particular requirements.

Upvotes: 5

Related Questions