Hayi
Hayi

Reputation: 6236

How to select a checkbox jquery object

Why my jquery object didn't get checked with $('.checkall').checked = true ;
Here's a Fiddle.
UPDATE : working code

Upvotes: 0

Views: 47

Answers (3)

David Thomas
David Thomas

Reputation: 253308

This is a problem of mixing jQuery, and DOM, methods. jQuery doesn't have access to the .value property of the node, instead use:

$('.checkall').prop('checked',true);

Reference:

Upvotes: 4

Amit Joki
Amit Joki

Reputation: 59232

You need this:

$('.checkall').prop('checked',true);

Or:

$('.checkall')[0].checked = true ;

You would use .prop() to set the property of checked or directly covnert the jQuery element to HTMLElement and then directly set the value.

Upvotes: 3

Venkata Krishna
Venkata Krishna

Reputation: 15112

Use .prop()

$('.checkall').prop('checked',true)

Upvotes: 3

Related Questions