filmov
tv
jQuery live function

Показать описание
Link for all dot net and sql server video tutorial playlists
Link for slides, code samples and text version of the video
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
In this video we will discuss jQuery live() and die() functions.
We discussed how to perform event delegation, using on() method in Part 36 and using delegate() method in Part 37. Another way to perform event delegation is by using live() function.
With on() and delegate() functions the event gets bubbled up to the specified parent element, where as with live() function the event gets bubbled up all the way to the document object.
The example that we worked with in Part 37 and Part 38 is rewritten using live() and die() functions as shown below. Notice that, to perform event delegation we are using live() function and to stop event delegation we are using die() function.
<html>
<head>
<title></title>
</script>
<script type="text/javascript">
$(document).ready(function () {
$('li').live('click', function () {
$(this).fadeOut(500);
});
$('#btnAdd').on('click', function () {
$('ul').append('<li>New List Item</li>');
});
$('#btnUndelegate').on('click', function () {
$('li').die('click');
});
});
</script>
</head>
<body style="font-family:Arial">
<input id="btnAdd" type="button" value="Add a New List Item" />
<input id="btnUndelegate" type="button" value="Undelegate" />
<ul>
<li>List Item</li>
<li>List Item</li>
</ul>
</body>
</html>
live() function is deprecated in jQuery 1.7 and completely removed in jQuery 1.9. Everything that can be achieved with the following methods can be achieved by using .on() function.
live()
bind()
delegate()
So, if you are using jQuery 1.7 or higher version, jQuery recommends to use on() function.
Please note : Older versions of jQuery can be found on the Microsoft CDN
Link for slides, code samples and text version of the video
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
In this video we will discuss jQuery live() and die() functions.
We discussed how to perform event delegation, using on() method in Part 36 and using delegate() method in Part 37. Another way to perform event delegation is by using live() function.
With on() and delegate() functions the event gets bubbled up to the specified parent element, where as with live() function the event gets bubbled up all the way to the document object.
The example that we worked with in Part 37 and Part 38 is rewritten using live() and die() functions as shown below. Notice that, to perform event delegation we are using live() function and to stop event delegation we are using die() function.
<html>
<head>
<title></title>
</script>
<script type="text/javascript">
$(document).ready(function () {
$('li').live('click', function () {
$(this).fadeOut(500);
});
$('#btnAdd').on('click', function () {
$('ul').append('<li>New List Item</li>');
});
$('#btnUndelegate').on('click', function () {
$('li').die('click');
});
});
</script>
</head>
<body style="font-family:Arial">
<input id="btnAdd" type="button" value="Add a New List Item" />
<input id="btnUndelegate" type="button" value="Undelegate" />
<ul>
<li>List Item</li>
<li>List Item</li>
</ul>
</body>
</html>
live() function is deprecated in jQuery 1.7 and completely removed in jQuery 1.9. Everything that can be achieved with the following methods can be achieved by using .on() function.
live()
bind()
delegate()
So, if you are using jQuery 1.7 or higher version, jQuery recommends to use on() function.
Please note : Older versions of jQuery can be found on the Microsoft CDN
Комментарии