bind() attaches an event handler to a dom element. live(), attaches the event handler to a parent element (typically document) and uses a selector to determine if a event originated from an element that matches that selector and generates a event. its handy
to attach events to dynamic context or have common event handler.
note: live() was depreciated in 1.7 and shouldn't be used. use on() instead. see docs:
What is the difference between Bind() and Live() method of jQuery?
The Bind method only attaches events to elements which exist beforehand i.e. state of initialized document before the events are attached. If the selector condition is satisfied for an event afterward, bind() will not work on that function. It also won’t
work in the case if selector condition is removed from the element.
The Live attaches events not only to existing elements but also for the ones appended in the future as well but it won’t work in the case if selector condition is removed from the element.
I don't recommend you to use these two methods because they are already deprecated now. you can try to use on method instead.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
bind() attaches an event handler to a dom element. live(), attaches the event handler to a parent element (typically document) and uses a selector to determine if a event originated from an element that matches that selector and generates a event. its handy
to attach events to dynamic context or have common event handler.
note: live() was depreciated in 1.7 and shouldn't be used. use on() instead. see docs:
Member
115 Points
98 Posts
JQuery
Mar 02, 2020 05:43 AM|shaili shah|LINK
What is the difference between Bind() and Live() method of jQuery?
Consider this code :
<html>
<head>
<script src= "https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js">
</script>
</head>
<body>
<div class="content">
<p class="a">This is Statement 1.</p>
<script>
$(".a").live("click",function(){
$(this).css("color","red");
});
</script>
<p class="a">This is Statement 2.</p>
</div>
</body>
</html>
Same code for bind method just replace it with live method.
I got confused when to use bind and live method in jQuery.
Any assistance would be appreciated.
https://www.ifourtechnolab.com/asp-dot-net-enterprise-content-management
All-Star
58164 Points
15647 Posts
Re: JQuery
Mar 02, 2020 06:06 PM|bruce (sqlwork.com)|LINK
bind() attaches an event handler to a dom element. live(), attaches the event handler to a parent element (typically document) and uses a selector to determine if a event originated from an element that matches that selector and generates a event. its handy to attach events to dynamic context or have common event handler.
note: live() was depreciated in 1.7 and shouldn't be used. use on() instead. see docs:
https://api.jquery.com/live/
Contributor
3370 Points
1409 Posts
Re: JQuery
Mar 03, 2020 03:06 AM|samwu|LINK
Hi shaili,
The Bind method only attaches events to elements which exist beforehand i.e. state of initialized document before the events are attached. If the selector condition is satisfied for an event afterward, bind() will not work on that function. It also won’t work in the case if selector condition is removed from the element.
The Live attaches events not only to existing elements but also for the ones appended in the future as well but it won’t work in the case if selector condition is removed from the element.
I don't recommend you to use these two methods because they are already deprecated now. you can try to use on method instead.
More information about on method you can refer to this link: https://api.jquery.com/on/
Best regards,
Sam
Member
115 Points
98 Posts
Re: JQuery
Mar 03, 2020 08:56 AM|shaili shah|LINK
Thank you. Now I got that why I was getting error.
https://www.ifourtechnolab.com/asp-dot-net-enterprise-content-management