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, 2022 in Web Development by gaurav
• 23,260 points
1,383 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, 2022 by rajatha
• 7,680 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, 2022 in Web Development by gaurav
• 23,260 points
734 views
0 votes
0 answers

jQuery if checkbox is checked

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

Jun 29, 2022 in Web Development by gaurav
• 23,260 points
485 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, 2022 in Web Development by gaurav
• 23,260 points
489 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, 2022 in Web Development by gaurav
• 23,260 points
1,171 views
0 votes
1 answer

How to style a checkbox using CSS

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

answered Feb 17, 2022 in Others by Aditya
• 7,680 points
905 views
0 votes
0 answers

Get checkbox value in jQuery

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

May 24, 2022 in HTML by Kichu
• 19,040 points
387 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, 2022 in CSS by Edureka
• 12,690 points
599 views
0 votes
1 answer

Get checkbox value in jQuery

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

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