Carter
Carter

Reputation: 77

How to select all elements with a class that contains a str?

Im trying to select all <path>'s but only ones that conatin a class that INCLUDES a str.

as an example if i have 3 elements

<h1 class="hello"/>
<h2 class="bye" />
<h3 class="fix" />

I want to be able to say everything with a class containing an e, change color to red.

which would make h1 and h2 red.

Im using d3.selectAll(path[class=*.${str}]);

(Doing this with d3.selectAll(path:not([class=*.${str}])`) seems to work for selecting everything without that class)

Upvotes: 1

Views: 83

Answers (1)

Tanner
Tanner

Reputation: 2421

Like Pete said, your * is on the wrong side of the equal sign. You also don't need to add . in your selector. Something like this should work for you:

d3.selectAll(`path[class*=${str}]`)

Upvotes: 3

Related Questions