Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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;
 
PREVIOUS NEXT
Tagged: #custom #attribute #react
ADD COMMENT
Topic
Name
3+4 =