Passing additional parameters to JQuery bind event function

Posted by kazim sardar mehdi on Geeks with Blogs See other posts from Geeks with Blogs or by kazim sardar mehdi
Published on Mon, 31 Jan 2011 10:23:50 GMT Indexed on 2011/01/31 15:26 UTC
Read the original article Hit count: 364

Filed under:
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>

© Geeks with Blogs or respective owner