Is it possible to disable certain action of an HTML element with a certain class via jQuery?

7

In my initialization I hedge all links should block using the

asked by anonymous 21.02.2014 / 19:01

2 answers

2

The answer would be to not link the event to the links as below:

$("a:not(.ui-multiselect-none, .ui-multiselect-all, .ui-multiselect-close)").on("click", $.blockUI);

Source: link

    
21.02.2014 / 21:27
0

Returning a false value will prevent the default option of the link and other events as well:

$("a.ui-multiselect-none, a.ui-multiselect-all, a.ui-multiselect-close").on("click", function(e) {
    return false;
});

However if you want to avoid only the action of other events, keeping the default action of the link use this:

$("a.ui-multiselect-none, a.ui-multiselect-all, a.ui-multiselect-close").on("click", function(e) {
    e.stopPropagation();
});

Still, it may occur, depending on the way your code is organized, that the above function does not prevent the default link action from being disabled by other functions. In this case use the first option, with a change: before return false simulate the default action of the link with window.location.replace(this.href); .

Still, one last alternative:

$("a").on("click", function () {
  var classes = 'ui-multiselect-none ui-multiselect-all ui-multiselect-close'.split(' ');
  while (classes.length) {
    if (this.hasClass(classes.pop())) {
      return true;
    }
  }
  $.blockUI();
});
    
21.02.2014 / 19:44