Answers for "how to get custom attribute value in react"

3

react data attributes event

const removeId = e.target.getAttribute("data-remove");
Posted by: Guest on August-31-2020
0

how to get custom attribute value in react

//To Define the Custom attribute
// start with data- Like: data-remove={someValue}
<button onClick={this.removeItem} data-remove={item.id}>Remove</button>

//To Get Custom Attribute value
// Method 1:
const removeId = e.target.dataset.remove;
// Method 2:
const removeId = e.target.getAttribute("data-remove");
// Method 3:
const removeId = e.target.attributes.getNamedItem("data-remove").value;
Posted by: Guest on July-13-2021

Code answers related to "how to get custom attribute value in react"

Code answers related to "Javascript"

Browse Popular Code Answers by Language