Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

e.target.id not working react js

//Well if the elements are nested event.target won't 
//always work since it refers to the target that triggers the 
//event in the first place. See this link for the usage of event.currentTarget, 
//which always refer to the element that the handler is bound to.

class Button extends React.Component {

    getButtonId = (e) => {
      console.log(e.currentTarget.id);
    }

    render() {
       return (
          <button id="yourID" onClick={this.getButtonId}>Button</button>
       );
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to give placeholder in input type date in angular 
Javascript :: js insert html 
Javascript :: deleting an instance in sequelize 
Javascript :: change the origin of html canvas 
Javascript :: dropdown item from the list flutter 
Javascript :: how sum all array element with while loop 
Javascript :: how a message persist in the localstorage in javascript 
Javascript :: how to create a blob javascript 
Javascript :: programmatically create a custom cron job drupal 7 
Javascript :: mongoose create populate response 
Javascript :: react qurery jest test mock queryClientProvider 
Javascript :: yup.array not working 
Javascript :: quasar router authentication 
Javascript :: Datatable shows No data available in table in angular 
Javascript :: full form of json 
Javascript :: Material-ui cold icon 
Javascript :: Resize Image Using HTML Canvas in JavaScript 
Javascript :: ejs tutorial 
Javascript :: kaboom.js 
Javascript :: regular expression url 
Javascript :: vue.js props undefined type 
Javascript :: how to convert string to pascal case in javascript 
Javascript :: Kendo Grid export to Excel not working with large data 
Javascript :: cross origin http://localhost forbidden jest 
Javascript :: javascript length of array 
Javascript :: cannot read property of undefined reading create material ui 
Javascript :: The element.appendChild() Method 
Javascript :: javascript window location 
Javascript :: mongoose discriminator 
Javascript :: {"statusCode":400,"error":"Bad Request","message":"Unexpected token o in JSON at position 1"} 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =