Home  >  Article  >  Web Front-end  >  How to use jquery on()

How to use jquery on()

coldplay.xixi
coldplay.xixiOriginal
2020-11-20 11:28:251273browse

Usage of jquery on(): The [on()] method adds one or more event handlers on the selected element and child elements. The syntax is [$(selector).on(event,childSelector, data, function)].

How to use jquery on()

##Usage of jquery on():

Definition and usage

on() method adds one or more event handlers on the selected element and sub-elements.

Since jQuery version 1.7, the on() method is the new replacement for the bind(), live(), and delegate() methods. This method brings a lot of convenience to the API and is recommended because it simplifies the jQuery code base.

Note: Event handlers added using the on() method apply to current and future elements (such as new elements created by scripts).

Tip: If you need to remove the event handler, use the off() method.

Tip: If you need to add an event that only runs once and then remove it, use the one() method.

Syntax

$(selector).on(event,childSelector,data,function)

Example

Add a click event handler to the

e388a4556c0f65e1904146cc1a846bee element :

$(document).ready(function(){
  $("p").on("click",function(){
    alert("段落被点击了。");
  });
});

Related free learning recommendations:

JavaScript (video)

The above is the detailed content of How to use jquery on(). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn