How to remove an attribute in D3.js?

bonna picture bonna · Mar 10, 2013 · Viewed 28.6k times · Source

Can I in D3.JS remove an attribute? I've added it using .attr("disabled", "disabled") and now I am looking for something similar to jQuery's .removeAttr("disabled", "disabled"); to remove it again. Useful for <button> and <option>. I've tried using the .remove() but that removes the entire object not the attribute.

Answer

Ian Roberts picture Ian Roberts · Mar 10, 2013

From the API documentation for attr

A null value will remove the specified attribute

So it looks like you want .attr('disabled', null).