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.
Use the removeAttribute() to remove an attribute from a specified element. Setting the value of a Boolean attribute to false will not work; use the removeAttribute() method instead.
Perform the delete in one of the following ways: ◦ From the Attributes tab, select the attribute that you want to delete, and click the delete icon . ◦ Right-click on the attribute on the Attributes tab, and select Delete. ◦ On the attribute information page, select Delete from the Actions menu for the attribute.
enter() function creates the initial join of the data with our DOM elements. Thus selecting only the elements that were not in the DOM yet. merge() function will select the DOM elements that did not exist in the DOM before and the ones that did. exit() function will select the DOM elements that are left from the join.
To remove all attributes of elements, we use removeAttributeNode() method.
From the API documentation for attr
A null value will remove the specified attribute
So it looks like you want .attr('disabled', null)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With