Home >Web Front-end >JS Tutorial >Usage examples of die() method in jQuery

Usage examples of die() method in jQuery

巴扎黑
巴扎黑Original
2017-06-30 13:56:561504browse

This article mainly introduces the usage of the die() method in jQuery. The example analyzes the function, definition and removal of all the die() method added to the specified element through the live() method. For tips on using multiple event handling programs, friends in need can refer to

This article explains the usage of the die() method in jQuery with examples. Share it with everyone for your reference. The specific analysis is as follows:

This method removes all one or more event handlers added to the specified element through the live() method.

Grammar structure:

The code is as follows:

$(selector).die(type,function)

Parameter list:

Parameter Description
type Optional. Defines one or more event types to attach to the element. Multiple event values ​​separated by spaces.
function Defines a function to run when an event occurs.

Example code:

The code is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.jb51.net/" />
<title>脚本之家</title>
<style type="text/css">
p{border:1px solid blue;}
li 
{
  
list-style-type
:none;
  width:150px;
  height:150px;
  border:1px solid green;
}
</style>
<script type="text/
javascript
" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript"> 
$(
document
).ready(function(){ 
  $("p").live("click",function(){ 
    $("li").slideToggle(); 
  }); 
  $("button").click(function(){ 
    $("p").die(); 
  }); 
}) 
</script>
</head>
<body>
<p>
  <ul>
    <li>脚本之家</li>
  </ul>
</p>
<button>删除添加</button>
</body>
</html>


The above is the detailed content of Usage examples of die() method in jQuery. 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