Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML make regular buttons act like a group of radio buttons

I want to get some "regular" buttons to act like a group of radio buttons.

I found a jQueryUI plugin that does exactly what I want: http://jqueryui.com/demos/button/#radio

But I'd like to avoid adding another library to my project. Any idea how this could be done using pure HTML + javascript/jQuery ?

Thanks in advance

like image 983
Adrien Be Avatar asked Oct 29 '25 19:10

Adrien Be


1 Answers

demo: http://jsfiddle.net/CXrgm/6

$('.button').click(function() {
   $('.button').removeClass('active');
   $(this).addClass('active');
});

where .button is your marker class for all buttons you need to include, and .active class whitch is indicate selected button.

to get the selected button use:

$('.button.active') // get attribute value, etc. Whatever you need.
like image 108
Samich Avatar answered Nov 01 '25 08:11

Samich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!