Geeks With Blogs
kazim mehdi
To pass the additional parameter to the event function pass an array of  key value, as the second parameter to the bind event
bind('click', { message: time }, onClick); 
e.g 
{ message: time }
and access it in the function 
using event<function parameter>.data.message<key>
 
<div id="div1" style="border: 1px solid black; width: 100px; height: 100px">
click me
</div>

<script type="text/javascript">         
function onClick(event)
{
alert(event.data.message);
}

var time = "loaded at:" + new Date().toString();
$("div.#div1").bind('click', { message: time }, onClick);
</script>

 

Posted on Monday, January 31, 2011 11:23 AM jquery , Javascript | Back to top


Comments on this post: Passing additional parameters to JQuery bind event function

# re: Passing additional parameters to JQuery bind event function
Requesting Gravatar...
This was very very helpful...
But, 1 question, the way we write delegates in C# [I mean adding additional handlers using += or removing the handlers using -=], is that possible in JQuery?
Left by Venkat on Jul 09, 2011 12:27 AM

# re: Passing additional parameters to JQuery bind event function
Requesting Gravatar...
I don't think so.
Left by kazim on Jul 28, 2011 3:39 PM

# re: Passing additional parameters to JQuery bind event function
Requesting Gravatar...
In the first place, I don't know what is the importance of caching. Is this the same with storing? I am not quite sure though. - Marla Ahlgrimm
Left by Marla Ahlgrimm on Feb 21, 2012 12:57 AM

Your comment:
 (will show your gravatar)


Copyright © kazim sardar mehdi | Powered by: GeeksWithBlogs.net