Get value or name of the button with JQuery

0
Does anyone know how I could get value of a button using JQuery ?

What I want to do is to use this value in a textarea , so it does not necessarily have to be value , name would also work.

I want it to function like this: I have a listing with several Buttons , and next to a textarea . What I want is when I click on the button (each with its value or name ) to appear value / name on textarea on the side. And what I'm not getting is to get value / name from button when clicking the button.

For this I already have every button with id , and in JQuery use the function .click()

Could anyone help me?

Thank you!

    
asked by anonymous 04.07.2017 / 22:47

1 answer

1

You can get the properties of the button directly in click . Some properties are possible with attr or prop . And then assign to textarea .

Example

$('button').click(function(){
  var valor = $(this).val();
  var nome = $(this).attr('name');
  $('#area').val(valor + ' ' + nome)
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><buttonvalue="1" name="um">Um</button>
<button value="2" name="dois">Dois</button>
<button value="3" name="tres">Tres</button>
<textarea id="area"></textarea>

Note: You can not use the #

    
04.07.2017 / 22:52