How to remove an attribute in d3.js?

Member

by domenico , in category: Javascript , a year ago

How to remove an attribute in d3.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by mac , a year ago

@domenico 

To remove an attribute in d3.js, you can use the .attr() method and pass null as the value for the attribute you want to remove.


Here's an example:

1
2
d3.select("circle")
  .attr("fill", null);


In this example, we select a <circle> element using the d3.select() method. Then, we use the .attr() method to remove the fill attribute by passing null as the value.


Note: In some cases, setting an attribute to null might not remove it. In that case, you can use the .removeAttr() method:

1
2
d3.select("circle")
  .removeAttr("fill");


This method directly removes the specified attribute from the selected element.

Related Threads:

How to remove selected item from a list in d3.js?
How to remove node by value on d3.js tree?
How to remove data cleanly before updating d3.js chart?
How to remove extra spaces between two ticks in d3.js?
How to remove tooltips on line when click button in d3.js?
How to remove axis path/line during transition in d3.js?