Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unrecognized expression: :[type=checkbox] with jQuery 1.8

I update the code to jQuery 1.8 and I start getting this error:

unrecognized expression: :[type=checkbox]

Of course this is say that the expression :[type=checkbox] is not recognized by the new version of jQuery and my question is:

I have type it the wrong way, or it's a bug ?

I have make this version for test on jsFiddle http://jsfiddle.net/4y8tb/6/ , open the console to see the log, and if you change the jQuery version you see it one to work and one not.

I have try some other syntax (like :[type="checkbox"]) but fails.

like image 741
Aristos Avatar asked Aug 13 '12 10:08

Aristos


People also ask

How do I mark a checkbox as checked in jQuery?

$('#checkboxid').is(':checked'); This will return true if the checkbox is checked and false if left unchecked.

How do I check if a checkbox is enabled in JavaScript?

In JavaScript, we can access the checkbox element using id, class, or tag name and apply '. checked' to the element, which returns either true or false based on the checkbox is checked.

Is checkbox checked jQuery by ID?

When the Check Button is clicked, the CheckBox will be first referenced using its ID and then the status of the CheckBox i.e. checked (selected) or unchecked (unselected) will be determined using JavaScript and jQuery.

Which checkbox is checked JavaScript?

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.


2 Answers

Change this:

$('input:[type=checkbox]')

To:

$('input[type=checkbox]')

You are using Attribute Equals selector, the syntax should be:

$('element[attribute="value"]')
like image 197
undefined Avatar answered Oct 03 '22 03:10

undefined


jQuery has an own pseudoselector for checkboxes:

$(':checkbox')
like image 21
Andy Avatar answered Oct 03 '22 03:10

Andy