0

I'm trying to check a box using jQuery. I've looked at some of the answers on this site but none of them worked (or I'm doing it wrong).

Here is the DOM

<input type="checkbox" id="ckbx_81861252,uFT1" name="memberIds" class="memberIds" value="81861752,uGT2">

When I click the box on the page, I don't see anything being updated in the DOM. Can anyone explain why? Or maybe I'm just missing it?

I tried both using .prop & .attr but neither checked the box.

Any help would be appreciated!

Morgan Allen
  • 3,291
  • 8
  • 62
  • 86

3 Answers3

1

its probably your comma. You have to escape it.

    $('#ckbx_81861252\\,uFT1').prop('checked', true);
Darkmere
  • 60
  • 4
0

If you click on the checkbox it should automatically toggle its checked state. If you want it with jQuery then try:

  • To check: $('input[name="memberIds"]').prop('checked', true);
  • To Uncheck: $('input[name="memberIds"]').prop('checked', false);
Deepak Biswal
  • 4,280
  • 2
  • 20
  • 37
0

You are having issues because of your id:

Fiddle 1

Fiddle 2

Look at both fiddles and notice the difference is the id...

Try a different ID:

<input type="checkbox" id="1" class="memberIds">
brso05
  • 13,142
  • 2
  • 21
  • 40