What is the use delegate() method in jquery

Posted by Jitendrasoft09 under C# on 6/26/2013 | Points: 10 | Views : 766 | Status : [Member] [MVP] | Replies : 3
Hi All,
I want to understand What is the use delegate() method in jquery, let me know if anybody knows.

Jitendra Kumar
If my post helps you, plz mark as an answer.



Responses

Posted by: Satyapriyanayak on: 6/27/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
The delegate() method attaches one or more event handlers for specified elements that are children of selected elements, and specifies a function to run when the events occur.


http://jquerybyexample.blogspot.com/2010/08/jquery-delegate-function-exampledemo.html

http://www.w3schools.com/jquery/event_delegate.asp

If this post helps you mark it as answer
Thanks

Jitendrasoft09, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 6/28/2013 [Member] Starter | Points: 25

Up
0
Down
The delegate() method attaches one or more event handlers for specified elements that are children of selected elements, and specifies a function to run when the events occur.

Event handlers attached using the delegate() method will work for both current and FUTURE elements (like a new element created by a script).
For C#
http://www.aspnetcodes.com/2013/06/delegates-in-c.html

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Jitendrasoft09, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raj.Trivedi on: 6/29/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello Jitendra

The delegate method was introduced with Jquery 1.4.2

It attachs a handler to specified elements


What we will do is we will try to execute the click function of td of table

Here is it

<script src="Scripts/jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function(){
$("table").delegate("td","click",function(){
alert('I am' + $(this).text());
});
});
</script>


<table border="2">
<tr>
<td>Dot Net</td>
<td>Java</td>
</tr>
<tr>
<td>C #</td>
<td>VB</td>
</tr>
</table>

If you check we have used delegate method and i have specified element td and then i have append click event then we have written a alert function and we are calling the text in alert.




Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Jitendrasoft09, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response