How to select only 1 button with jQuery?

0

I have a certain amount of buttons on the same div, how would you do so that you only let me select only 1 at a time? and save the value of the selected button?

    
asked by 17.12.2017 в 01:44
source

1 answer

0

Good friend, I really do not understand what you mean by how would you do so that you only let me select only 1 at a time?

I leave you several examples of how to get data with jquery

  

NOTE: I enable the input[type="checkbox"] because I think you need only one selected. if this is not the case, the user could select the 3 input .

$(".con-checks").find("input[type='checkbox']").change(function(){
  $(".con-checks").find("input[type='checkbox']").attr("disabled",true)
  console.log($(this).val())
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="con-checks">
<input id="check1" type="checkbox" name="" value="check 1">
<label for="check1">Check 1</label>

<input id="check2" type="checkbox" name="" value="check 2">
<label for="check2">Check 2</label>

<input id="check3" type="checkbox" name="" value="check 3">
<label for="check3">Check 3</label>
<div>

$(".con-radios").find("input[type='radio']").change(function(){
  console.log($(this).val())
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="con-radios">
<input id="radio1" type="radio" name="radios" value="Radio 1">
<label for="radio1">Radio 1</label>

<input id="radio2" type="radio" name="radios" value="Radio 2">
<label for="radio2">Radio 2</label>

<input id="radio3" type="radio" name="radios" value="Radio 3">
<label for="radio3">Radio 3</label>
<div>

$(".btns").click(function(){
  console.log($(this).text())
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="btns" type="button" name="button">Boton 1</button>
  <button class="btns" type="button" name="button">Boton 2</button>
  <button class="btns" type="button" name="button">Boton 3</button>

Let me know if it's what you need or what changes you need to help you friend.

    
answered by 17.12.2017 / 02:06
source