1

I have a checkbox element with id #tmcp_choice_5_0_22

And and have this code which works fine:

$('input#tmcp_choice_5_0_22').click(function(){
    alert('Does this work?');
});

Problems happens when the checkbox is 'disabled', it seems that the click() function doesn't work in disabled elements.

Is there other function I could use for this instead of click()?

The duplicated question doesn't help me, because I can not put another element in the HTML, the html code is generated by a wordpress plugin.

JPashs
  • 13,044
  • 10
  • 42
  • 65

1 Answers1

2

IMHO the simplest, cleanest way to "fix" this (if you do in fact need to capture clicks on disabled elements like the OP does) is just to add the following CSS to your page:

input[disabled] {pointer-events:none}

This will make any clicks on a disabled input fall through to the parent element, where you can capture them normally. (If you have several disabled inputs, you might want to put each into an individual container of its own, if they aren't already laid out that way - an extra <span> or a <div>, say - just to make it easy to distinguish which disabled input was clicked).

Source: https://stackoverflow.com/a/32925830/2518200

Cave Johnson
  • 6,499
  • 5
  • 38
  • 57