0

How to set opacity:1 for "labelwebmetro.com" class using d3 js.

<g class="circle" transform="translate(686.7254745357253,1011.2761564139669)">
<text x="12" dy=".35em" class="labelwebmetro.com" style="opacity: 0;">webmetro.com</text>
<circle style="fill: rgb(255, 127, 14);" r="40" class="circlewebmetro.com"/>
</g>
Shahzad Barkati
  • 2,532
  • 6
  • 25
  • 33
Musakkhir Sayyed
  • 7,012
  • 13
  • 42
  • 65

2 Answers2

2

You can use selection.style on selector as,

d3.select("g text.myClass").style("opacity", 1);

The thing is class name labelwebmetro.com may not work because it contains a dot(.) however you can give it a try. If you can replace it somehow with something more clean it would be good. Besides class name with dot(.) is not cross browser supported i believe.

Check this out how to use a CSS class with a dot.

Community
  • 1
  • 1
Rohit416
  • 3,416
  • 3
  • 24
  • 41
0

d3.select selects first element with given criteria. In this case, we are looking for text with class specific class. Then style function modifies style of the selection.

d3.select('text.labelwebmetro.com').style('opacity', 1.0);

If you want to change every element with class labelwebmetro.com, then you could do

d3.selectAll('.labelwebmetro.com').style('opacity', 1.0);
baklazan
  • 814
  • 6
  • 13