jQuery Summary of Common Methods for Removing or Disabling html Element Click Events

  • 2021-07-18 06:45:43
  • OfStack

This article illustrates a common way for jQuery to remove or disable html element click events. Share it for your reference, as follows:

The click event to remove or disable an html element can be implemented via css, js or jQuery.

1. CSS method

.disabled { pointer-events: none; }

2. jQuery method

Method 1


$(this).click(function (event) {
event.preventDefault();
}

Method 2


$('a').live('click', function(event) {
   alert(" Sorry , Deactivated! ");
   event.preventDefault();
});

Note: live in this method can also be on, bind, etc

Method 3


$('.disableCss').removeAttr('onclick');// Remove the onclick Events 

The removeAttr method is used to control the html tag property has reached the enabled or disabled event. In addition, other events or other effects can be controlled in this way.

Method 4


$('#button').attr('disabled',"true");// Add disabled Attribute 
$('#button').removeAttr("disabled"); // Remove disabled Attribute 

Note: Method 3 is the same as Method 3, but disabled attribute 1 is generally used on input of type button or submit

PS: Here is an online comparison table of javascript common events and function descriptions for your reference:

javascript Events and Functional Description Encyclopedia:
http://tools.ofstack.com/table/javascript_event

For more readers interested in jQuery related content, please check the topics of this site: "Summary of Usage and Skills of Common Events of jQuery", "Summary of Common Plug-ins and Usage of jQuery", "Summary of Data Skills of jQuery Operation json", "Summary of Extension Skills of jQuery", "Summary of Drag and Drop Special Effects and Skills of jQuery", "Summary of Operation Skills of jQuery Table (table)", "Summary of Common Classic Special Effects of jQuery", "Summary of Animation and Special Effects Usage of jQuery" and "Usage of jquery Selector"

I hope this article is helpful to everyone's jQuery programming.


Related articles: