jQuery how to check if event is already bound
Link for all dot net and sql server video tutorial playlists
https://www.youtube.com/user/kudvenkat/playlists?sort=dd&view=1
Link for slides, code samples and text version of the video
http://csharp-video-tutorials.blogspot.com/2015/05/jquery-how-to-check-if-event-is-already.html
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.
https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation=1
In this video we will discuss, how to check if an event is already bound using jQuery.
Why is it important to check if an event is already bound
To prevent attaching event handler multiple times
The following example checks if a click event handler is already bound. If it's not already bound, then a click event handler is attached.
Replace < with LESSTHAN symbol and > with GREATERTHAN symbol
<html>
<head>
<title></title>
<script src="jquery-1.11.2.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var jQueryObject = $('#btn');
var rawDOMElement = jQueryObject.get(0);
var eventObject = $._data(rawDOMElement, 'events');
if (eventObject != undefined && eventObject.click != undefined) {
alert('Click event exists');
}
else {
$('#btn').on('click', function () {
alert('Button Clicked');
});
}
});
</script>
</head>
<body style="font-family:Arial">
<input id="btn" type="button" value="Click Me" />
</body>
</html>
Please note that this only works if you have attached event handlers using jQuery. This will not work if you have attached event handlers using raw JavaScript or element attributes.
Another way to prevent attaching event handlers multiple times is by using jQuery off() and on() methods. The off() method ensures that all existing click event handlers of the button are removed before again adding a new click event handler using on() method.
$('#btn').off('click').on('click', function () {
alert('Button Clicked');
});
Видео jQuery how to check if event is already bound канала kudvenkat
https://www.youtube.com/user/kudvenkat/playlists?sort=dd&view=1
Link for slides, code samples and text version of the video
http://csharp-video-tutorials.blogspot.com/2015/05/jquery-how-to-check-if-event-is-already.html
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.
https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation=1
In this video we will discuss, how to check if an event is already bound using jQuery.
Why is it important to check if an event is already bound
To prevent attaching event handler multiple times
The following example checks if a click event handler is already bound. If it's not already bound, then a click event handler is attached.
Replace < with LESSTHAN symbol and > with GREATERTHAN symbol
<html>
<head>
<title></title>
<script src="jquery-1.11.2.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var jQueryObject = $('#btn');
var rawDOMElement = jQueryObject.get(0);
var eventObject = $._data(rawDOMElement, 'events');
if (eventObject != undefined && eventObject.click != undefined) {
alert('Click event exists');
}
else {
$('#btn').on('click', function () {
alert('Button Clicked');
});
}
});
</script>
</head>
<body style="font-family:Arial">
<input id="btn" type="button" value="Click Me" />
</body>
</html>
Please note that this only works if you have attached event handlers using jQuery. This will not work if you have attached event handlers using raw JavaScript or element attributes.
Another way to prevent attaching event handlers multiple times is by using jQuery off() and on() methods. The off() method ensures that all existing click event handlers of the button are removed before again adding a new click event handler using on() method.
$('#btn').off('click').on('click', function () {
alert('Button Clicked');
});
Видео jQuery how to check if event is already bound канала kudvenkat
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
Part 48 Controlling WCF message protection using ProtectionLevel parameterDateTime2FromParts function in SQL Server 2012Cloud computing course introductionShow or hide login and logout links based on login status in asp net coreASP NET core identity password complexityStyle binding in angular 2AngularJS caseInsensitiveMatch and Inline TemplatesViewImports cshtml in ASP NET Core MVCWhat is AutoMapper and using it in ASP NET CoreWhen to use azure virtual machinesexec vs sp executesql in sql serverASP NET Core LogLevel configurationWhat is heap table | Full table scanKey lookup and RID lookup in sql server execution plansASP NET core razor componentsOpen redirect vulnerability exampleLogging deadlocks in sql serverDifference between union intersect and except in sql serverEdit role in asp net coreAzure tutorial for beginnersViewModel in ASP NET Core MVC