d3.selectAll logical NOT

6,417 views
Skip to first unread message

Andrew Bucin

unread,
May 29, 2012, 1:30:57 PM5/29/12
to d3...@googlegroups.com
Hello everyone,

I was wondering if there is a way to select anything BUT a certain element. The documentation on GitHub contains information about logical OR and logical AND but no info on logical NOT selections. I've looked into filters but I can't seem to wrap my mind around how to target a specific class (from within the filter). Back to my problem, say that I have the following:

<svg>
<child class='a_class'></child>
<child class='b_class'></child>
<child class='c_class'></child>
</svg>


The idea is I want to select all of svg's children, except the one with the class b_class. How can I achieve that using d3.selectAll() ?

Please excuse the crude representation :)

Jason Davies

unread,
May 29, 2012, 1:38:46 PM5/29/12
to d3...@googlegroups.com
On Tue, May 29, 2012 at 10:30:57AM -0700, Andrew Bucin wrote:
> I was wondering if there is a way to select anything BUT a certain element.
> The documentation on GitHub contains information about logical OR and
> logical AND but no info on logical NOT selections. I've looked into filters
> but I can't seem to wrap my mind around how to target a specific class
> (from within the filter). Back to my problem, say that I have the following:
>
> *<svg>
> <child class='a_class'></child>
> <child class='b_class'></child>
> <child class='c_class'></child>
> </svg>*
>
> The idea is I want to select all of *svg's* children, *except* the one with
> the class *b_class*. How can I achieve that using d3.selectAll() ?

Use the CSS3 :not pseudo-class [1]:

d3.select("svg").selectAll("*:not(.b_class)");

[1]: http://www.w3.org/TR/selectors/#negation
--
Jason Davies, http://www.jasondavies.com/

Andrew Bucin

unread,
May 29, 2012, 3:01:32 PM5/29/12
to d3...@googlegroups.com
It worked! Thanks!
Reply all
Reply to author
Forward
0 new messages