N
N
nano_e_t_42019-05-07 15:34:17
JavaScript
nano_e_t_4, 2019-05-07 15:34:17

How to get button attributes?

There is this piece of code:

<div className="pBtn">
                  <Button
                      block
                      bsSize="large"
                      onClick={props.arrowHandler}
                      id="la-la-la"
                      value={1}
                  >
                      <Image src={require('../../styles/iconcs/arrow.png')} fluid />;
                  </Button>
                  </div>

...
    arrowHandler = event => {
        console.log(event)
    }

How to get the attributes of the button, in particular the value value?
A call to the target element ( event.target.value) returns the value of the element nested in the button instead of the value of the button itself.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2019-05-07
@nano_e_t_4

currentTarget : Or, there is an option not to set the attribute at all, but to pass the desired value to the handler (no, I wouldn’t do it myself - an extra function is created, plus you have to rewrite the handler):
event.currentTarget.getAttribute('имя_атрибута')
onClick={e => props.arrowHandler(e, VALUE)}

A
Alex, 2019-05-07
@Kozack

And so?console.log(this.value)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question