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,065
  • 5
  • 50
  • 81

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,190
  • 2
  • 18
  • 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
  • 12,924
  • 2
  • 19
  • 39