get value of several buttons with JQUERY


hello guys I have a total of 10 buttons which have a value that I want to extract their value with a click depending on which is the clicked vote I'm doing with jquery but I do not know what I'm doing wrong here my code:

 $("#evaluate button").click(function(){


 <div id="evaluate">
      <button value="1"><b>1</b> </button>
      <button value="2"><b>2</b> </button>
      <button value="3"><b>3</b> </button>
      <button value="4"><b>4</b> </button>
      <button value="5"><b>5</b> </button>
      <button value="6"><b>6</b> </button>
      <button value="7"><b>7</b> </button>
      <button value="8"><b>8</b> </button>
      <button value="9"><b>9</b> </button>
      <button value="10"><b>10</b> </button>

thanks any help I thank you very much

asked by andy gibbs 01.07.2018 в 21:29

2 answers


I commented to you that I tested your code and it is functional about what you request, what you must keep in mind is that first the call to jquery must go and then the script with which you get the value look

<!DOCTYPE html>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
<div id="evaluate">
      <button id="val1" value="1"><b>1</b> </button>
      <button id="val2" value="2"><b>2</b> </button>
      <button id="val3" value="3"><b>3</b> </button>
      <button id="val4" value="4"><b>4</b> </button>
      <button id="val5" value="5"><b>5</b> </button>
      <button id="val6" value="6"><b>6</b> </button>
      <button id="val7" value="7"><b>7</b> </button>
      <button id="val8" value="8"><b>8</b> </button>
      <button id="val9" value="9"><b>9</b> </button>
      <button id="val10" value="10"><b>10</b> </button>
<script src=""></script>

     $("#evaluate button").click(function(){


answered by 01.07.2018 / 21:46

You can put a class common to all the buttons and detect which one you click directly on.



 <div id="evaluate">
      <button class="class-button" id="val1" value="1"><b>1</b> </button>
      <button class="class-button" id="val2" value="2"><b>2</b> </button>
      <button class="class-button" id="val3" value="3"><b>3</b> </button>
      <button class="class-button" id="val4" value="4"><b>4</b> </button>
      <button class="class-button" id="val5" value="5"><b>5</b> </button>
      <button class="class-button" id="val6" value="6"><b>6</b> </button>
      <button class="class-button" id="val7" value="7"><b>7</b> </button>
      <button class="class-button" id="val8" value="8"><b>8</b> </button>
      <button class="class-button" id="val9" value="9"><b>9</b> </button>
      <button class="class-button" id="val10" value="10"><b>10</b> </button>
answered by 01.07.2018 в 21:42