Use the jquery bind method:
function myfunc(param) { alert(param.data.key); } $(document).ready( function() { $("#foo").bind('click', { key: 'value' }, myfunc); });
Also see my jsfiddle .
=== UPDATE ===
since jquery 1.4.3 you can also use:
function myfunc(param) { alert(param.data.key); } $(document).ready( function() { $("#foo").click({ key: 'value' }, myfunc); });
Also see my second jsfiddle .
=== UPDATE 2 ===
Each function has its own this
. After calling clearFmt
in this function, this
no longer a clearFmt
item. I have two similar solutions:
In your functions, add a parameter called, for example. element
and replace $(this)
with element
.
function clearFmt(element, fmt_type) { if (element.val() == fmt_type) { element.val(""); } }
When calling a function, you must add the $(this)
parameter.
$(date_field).click(function() { clearFmt($(this), date_fmt); });
Also see my third jsfiddle .
- = -
Alternative:
function clearFmt(o) { if ($(o.currentTarget).val() == o.data.fmt_type) { $(o.currentTarget).val(""); } } $(date_field).click({fmt_type: date_fmt}, clearFmt);
Also see my fourth jsfiddle .
source share