0

I have a checkbox on my page. How do I stop it from receiving any event (e.g. touchstart) using jQuery ?

I mean nothing should happen when that checkbox is clicked.

3 Answers 3

0

To disable all JavaScript - Handlers on the element:

$('#checkbox').unbind();

And to prevent the standard-function of the checkbox, you could disable it

$('#checkbox').attr('disabled', true);

or directly in the Markup:

<input type="checkbox" disabled="disabled" />
0

See this: jQuery unbind()

$('#thecheckbox').unbind('click'); // removes all 'click' event handlers from the element
0

Use this, but you have to specify the events one by one:

$('.selectorToCheckbox').bind('click mouseover', function (e) {
    e.preventDefault();
});

The available events are: blur, focus, focusin, focusout, load, resize, scroll, unload, click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, mouseenter, mouseleave, change, select, submit, keydown, keypress, keyup, error.

1
  • 1
    Why would you specify all of the handlers? jQuery API -> In the simplest case, with no arguments, .unbind() removes all handlers attached to the elements:
    – GNi33
    Aug 11, 2011 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.