button group get value

Solutions on MaxInterview for button group get value by the best coders in the world

showing results for - "button group get value"
Alejandro
10 Nov 2017
1<div class="btn-group" data-toggle="buttons-radio">
2        <button class="btn">1</button>
3        <button class="btn">2</button>
4        <button class="btn">3</button>
5        <button class="btn">4</button>
6</div>
7
8
9
10
11var num = null;
12var ele = document.querySelectorAll(".btn-group > button.btn");
13for(var i=0; i<ele.length; i++){
14    ele[i].addEventListener("click", function(){
15        num = +this.innerHTML;
16        alert("Value is " + num);
17    });
18}
19Or jQuery:
20
21var num = null;
22$(".btn-group > button.btn").on("click", function(){
23    num = +this.innerHTML;
24    alert("Value is " + num);
25});