-1

Here is my input:

<input name="my_checkbox" type="checkbox" value="1">

I'm trying to check/uncheck it via jquery:

this._holder.find('checkbox').prop('checked', true);

But this fails to work. I know this._holder.find is working as I am able to set this:

this._holder.find('input').val('whatever');

Where am I going wrong?

Huangism
  • 16,278
  • 7
  • 48
  • 74
panthro
  • 22,779
  • 66
  • 183
  • 324
  • 1
    `.find('checkbox')` checkbox is not an element – Huangism Sep 18 '14 at 16:08
  • 1
    CSS selectors 101 `"checkbox"` is looking for `` That is an element selector, not an attribute selector. – epascarello Sep 18 '14 at 16:09
  • this question is duplicate of hundreds of others... I don't mean to be rude, but did you even try googling this question? http://stackoverflow.com/questions/426258/how-do-i-check-a-checkbox-with-jquery/426276#426276 – Mike Sep 18 '14 at 16:11

2 Answers2

1

Your selector doesn't work because your element hasn't checkbox as tag.

Use

this._holder.find('[name=my_checkbox]').prop('checked', true);

or

this._holder.find('[type=checkbox]').prop('checked', true);
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
0
$(":checkbox").prop('checked',true);

Fiddle

Genjuro
  • 7,405
  • 7
  • 41
  • 61