Check if checkbox is checked with jQuery

0 votes

How can I check if a checkbox in a checkbox array is checked using the id of the checkbox array?

I am using the following code, but it always returns the count of checked checkboxes regardless of id.

function isCheckedById(id) {
    alert(id);
    var checked = $("input[@id=" + id + "]:checked").length;
    alert(checked);

    if (checked == 0) {
        return false;
    } else {
        return true;
    }
}

Jun 23 in Web Development by gaurav
• 18,960 points
79 views

1 answer to this question.

0 votes

To check whether a Checkbox has been checked, in jQuery, you can simply select the element, get its underlying object, instead of the jQuery object ( [0] ) and use the built-in checked property: let isChecked = $('#takenBefore')[0]. checked console. log(isChecked);

answered Jun 23 by rajatha
• 7,440 points

Related Questions In Web Development

0 votes
0 answers

jQuery: Test if checkbox is NOT checked

I'm having trouble figuring this out. I ...READ MORE

Jun 29 in Web Development by gaurav
• 18,960 points
56 views
0 votes
0 answers

jQuery if checkbox is checked

I have a function below that I ...READ MORE

Jun 29 in Web Development by gaurav
• 18,960 points
16 views
0 votes
0 answers

How to check radio button is checked using JQuery?

I have two radio buttons in one ...READ MORE

Jun 29 in Web Development by gaurav
• 18,960 points
37 views
0 votes
0 answers

jquery uncheck and check and vise versa checkbox of child element

Here is my html #This will be generated ...READ MORE

Jul 26 in Web Development by gaurav
• 18,960 points
23 views
0 votes
1 answer

How to style a checkbox using CSS

In modern browsers which include Internet Explorer ...READ MORE

answered Feb 17 in Others by Aditya
• 7,660 points
76 views
0 votes
0 answers

Get checkbox value in jQuery

How can I get a checkbox's value ...READ MORE

May 24 in HTML by Kichu
• 19,040 points
22 views
0 votes
1 answer

How to style a checkbox using CSS?

Add focus outline input[type="checkbox"]:focus + span:before { ...READ MORE

answered Jun 21 in CSS by Edureka
• 9,540 points
34 views
0 votes
1 answer

Get checkbox value in jQuery

To get the value of the Value ...READ MORE

answered Jun 23 in Web Development by rajatha
• 7,440 points
26 views
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP