Summary of common methods for jQuery to remove or disable html element click events, and jquery to remove

Source: Internet
Author: User
Tags comparison table

Summary of common methods for jQuery to remove or disable html element click events, and jquery to remove

This document describes how to use jQuery to remove or disable html element click events. We will share this with you for your reference. The details are as follows:

The click event for removing or disabling html elements can be implemented through css or js or jQuery.

I. CSS Method

. Disabled {pointer-events: none ;}

Ii. jQuery Method

Method 1

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

Method 2

$ ('A'). live ('click', function (event) {alert ("sorry, disabled! "); Event. preventDefault ();});

Note: live in this method can also be thought of as on, bind, and other methods.

Method 3

$ ('. DisableCss'). removeAttr ('onclick'); // remove the onclick event from the tag.

The removeAttr method is used to control the attribute of html tags to enable or disable events. In addition, you can use this method to control other events or other effects.

Method 4

$ ('# Click '). attr ('Disabled ', "true"); // Add the disabled attribute $ (' # click '). removeAttr ("disabled"); // remove the disabled attribute

Note: This is the same as method 3. However, the disabled attribute is generally used in the input of the button or submit type.

PS: the online comparison table of common javascript events and function descriptions is provided here for your reference:

Javascript events and functions:
Http://tools.jb51.net/table/javascript_event

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.