4

Binding a function on document all element having class SearchableCol

jQuery(document).on("click", ".SearchableCol", nwcsClickFunc);

I am trying below two methods to unbind, nothing is working.

jQuery(document).unbind("click", nwcsClickFunc);
jQuery(".SearchableCol").unbind("click");

Need help to unbind an event from document.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Anil
  • 3,722
  • 2
  • 24
  • 49

3 Answers3

10

Try

jQuery(document).off("click", ".SearchableCol", nwcsClickFunc);

or use namespaced event handlers

jQuery(document).on("click.myevent", ".SearchableCol", nwcsClickFunc);

then

jQuery(document).off("click.myevent", ".SearchableCol");
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
  • I also tried jQuery(document).on("click", ".SearchableCol").unbind(); and it also worked but off is better thanks...... – Anil Feb 20 '14 at 10:56
3
jQuery(document).off("click", ".SearchableCol", nwcsClickFunc);
Spokey
  • 10,974
  • 2
  • 28
  • 44
1

use:

$(".SearchableCol").unbind('click',nwcsClickFunc);

or

$(document).off('click','.SearchableCol',nwcsClickFunc);
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
  • 1
    the first one won't work for delegated event, handler bound to document level, not to ".SearchableCol" elements – A. Wolff Feb 20 '14 at 10:24
  • @A.Wolff: Not sure how it should be used. :\ – Milind Anantwar Feb 20 '14 at 10:27
  • Not sure to understand your comment, but your second solution is what OP is looking for ;) Remove the first and get a +1 – A. Wolff Feb 20 '14 at 10:28
  • What i mean is, is it possible to remove delegated events(on,live) using undelegate. – Milind Anantwar Feb 20 '14 at 10:30
  • 1
    ya, using namespace: `jQuery(document).off('click.namespace');` or just `jQuery(document).off('click');` but that will remove all click handlers bound to document – A. Wolff Feb 20 '14 at 10:32
  • Sorry forgot this one of course: `jQuery(document).off('click',nwcsClickFunc);` but again, not specific to `.SearchableCol` elements – A. Wolff Feb 20 '14 at 10:34