Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery 1.9 checkbox not checked second time after once it unchecked

Tags:

In jQuery 1.9 v checkbox is not checked, once I have unchecked it, trying to check again by clicking on button

$("#add_cart_checkbox").attr("checked",'checked') ; 
like image 706
Kheta Ram Sansi Avatar asked Jan 24 '13 05:01

Kheta Ram Sansi


People also ask

How check if checkbox is checked jQuery?

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);

How do I uncheck a specific checkbox in jQuery?

By using jQuery function prop() you can dynamically add this attribute or if present we can change its value i.e. checked=true to make the checkbox checked and checked=false to mark the checkbox unchecked.

How do I check uncheck all checkboxes with a button using jQuery?

Answer: Use the jQuery prop() method You can use the jQuery prop() method to check or uncheck a checkbox dynamically such as on click of button or an hyperlink etc. The prop() method require jQuery 1.6 and above.

How check if checkbox is checked?

Checking if a checkbox is checked First, select the checkbox using a DOM method such as getElementById() or querySelector() . Then, access the checked property of the checkbox element. If its checked property is true , then the checkbox is checked; otherwise, it is not.


1 Answers

You have to use prop, and pass it a boolean:

$("#add_cart_checkbox").prop("checked", true) ; 
like image 133
Joseph Silber Avatar answered Oct 12 '22 10:10

Joseph Silber