16

I am trying to use e.target.name in react to set the state as I have done before, however e.target.name seems to be undefined for some reason and I can't figure out why, if any one has a suggestion it will be welcome. thanks!

<li
    onMouseEnter={this.handleMouseEnter.bind(this)}
    name="HOME"
    id="some id"
    style={main.element}
>
    HOME
</li>    

my event handler has only a debugger for me to play with

handleMouseEnter(e) {
    debugger
}

and when i try to get the value of the name property i get undefined

e.target
//<li name=​"HOME" id=​"some id" style=​"padding:​ 10px;​">​HOME​</li>​
e.target.name
//undefined
e.target.id
//"some id"
Guilherme Samuel
  • 459
  • 6
  • 11
Nilos
  • 339
  • 1
  • 4
  • 13
  • 4
    `e.target.getAttribute('name')` – Ele Feb 26 '18 at 14:48
  • 1
    If you `console.log(e)` in your handler, what do you get out? – Phillip Thomas Feb 26 '18 at 14:51
  • 6
    The values like `id` are properties. There are some rules for different types of html elements the properties are different. For an `` element, `id`,`name`,`type` etc are valid. For `
  • ` tag the property `name` is not a valid one, hence `e.target.name` is undefined. You'll need to access it just like any other custom attributes.
  • – rrk Feb 26 '18 at 14:52
  • Thanks! this really clarify it! – Nilos Feb 26 '18 at 14:56