Currently, I am trying to make two buttons in the same way as radio buttons, where only one can be selected at a time.
HTML
<button class="button" value="purchase" name="selector_button_group">
Purchase
</button>
<button class="button" value="refinance" name="selector_button_group">
Refinance
</button>
JQuery
$("button[name=selector_button_group]").click(function() {
$("button[name=selector_button_group]").removeClass('active');
$(this).addClass('active');
});
Now we return the value of the selected button
var purchaseType = $("button[name=selector_button_group].active").val();
or
var purchaseType = $("button[name=selector_button_group]").hasClass('active').val();
However, this does not work and will not return a button with an active class. I also tried to use hasClass('active'), but I can’t figure out how to get this to find the active button with it.
zoruc source
share