Search
 
SCRIPT & CODE EXAMPLE
 

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;
Comment

PREVIOUS NEXT
Code Example
Javascript :: convert to datetime in jquery 
Javascript :: how to wait until a variable is set javascript 
Javascript :: difference between devDependency and dependency 
Javascript :: javascript insert last character of string 
Javascript :: js get element type 
Javascript :: how to parse json in java 
Javascript :: create infinite loop using for loop in javascript 
Javascript :: how to display text with formating react js 
Javascript :: get element or class 
Javascript :: NextJS PWA gitignore 
Javascript :: javascript send post 
Javascript :: react image compression 
Javascript :: react native linking email 
Javascript :: make select option selected javascript 
Javascript :: mongoose schema 
Javascript :: how to get date using tolocaledatestring 
Javascript :: javascript get random line from text file 
Javascript :: device width js 
Javascript :: adding new sass version 
Javascript :: timestamps in mongoose 
Javascript :: js sort 1 or -1 
Javascript :: javascript ascending and descending 
Javascript :: datatable hide columns 
Javascript :: replace string in javascript 
Javascript :: random color code js 
Javascript :: node get root directory 
Javascript :: react native scrollview detect end 
Javascript :: javascript compare sets 
Javascript :: js click element 
Javascript :: javascript querySelectorAll id ends with 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =