Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
jQuery click events in Bootstrap Button plugin

How can I determine which radio button is checked on click of a radio button using the Bootstrap Button plugin?

The following is evaluating to false no matter which radio button is selected:

HTML

<div class="btn-group" data-toggle="buttons" id="disabled-radio-btn">
    <label class="btn btn-default">
        <input type="radio" name="disabled" id="disabled-yes">Yes
    </label>
    <label class="btn btn-default">
        <input type="radio" name="disabled" id="disabled-no">No
    </label>
</div>

JS

$('#disabled-radio-btn').click(function (e) {
    if ($('#disabled-no:checked').length) {
        $('#SSDI').hide();
    }
    else {
        $('#SSDI').show();
    }
});
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

should be $('#disabled-no').is(':checked') in the if statement to check if the radio button is checked.

$('#disabled-radio-btn').click(function (e) {

    if ($('#disabled-no').is(':checked')) {
        $('#SSDI').hide();
    }
    else {
        $('#SSDI').show();
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="btn-group" data-toggle="buttons" id="disabled-radio-btn">
    <label class="btn btn-default">
        <input type="radio" name="disabled" id="disabled-yes">Yes
    </label>
    <label class="btn btn-default">
        <input type="radio" name="disabled" id="disabled-no">No
    </label>
</div>

<div id="SSDI">SSDI THING</div>

update: https://jsfiddle.net/7hrbcmnb/2/

use event delegation when declaring the click event

$(document).on('click', '#disabled-radio-btn', function (e) {});

about 4 years ago · Santiago Trujillo Report

0

Use the val() method with the checked attribute.

if($("#disabled-no:checked").val())

$('#disabled-radio-btn').click(function (e) {

    if ($('#disabled-no:checked').val()) {
        $('#SSDI').hide();
    }
    else {
        $('#SSDI').show();
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="btn-group" data-toggle="buttons" id="disabled-radio-btn">
    <label class="btn btn-default">
        <input type="radio" name="disabled" id="disabled-yes">Yes
    </label>
    <label class="btn btn-default">
        <input type="radio" name="disabled" id="disabled-no">No
    </label>
</div>

<div id="SSDI">SSDI THING</div>

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!