What is the usage of live in jquery

WBOY
Release: 2022-03-22 16:03:59
Original
1569 people have browsed it

In jquery, the live() method is used to add event handlers to elements and specify the function to be run when the event occurs. The syntax is "$(selector).live(event,data,function to run)" "; This method was removed in jquery version 1.9 and can be replaced by the on() method.

What is the usage of live in jquery

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

What is the usage of live in jquery

The live() method attaches one or more event handlers to the selected elements and specifies the functions to be run when these events occur.

Event handlers attached via the live() method apply to current and future elements matching the selector (such as new elements created by scripts).

Syntax

$(selector).live(event,data,function)
Copy after login

The parameters are expressed as follows:

event is required. Specifies one or more events to attach to the element. Multiple events separated by spaces. Must be a valid event.

data is optional. Specifies additional data to be passed to this function.

function required. Specifies a function to run when an event occurs.

The live() method is deprecated in jQuery version 1.7 and removed in version 1.9. Please use the on() method instead.

Examples are as follows:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").live("click",function(){
    $("p").slideToggle();
  });
});
</script>
</head>
<body>
<p>这是一个段落。</p>
<button>请点击这里</button>
</body>
</html>
Copy after login

Recommended related video tutorials: jQuery video tutorial

The above is the detailed content of What is the usage of live in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!