This would depend on what "arguments" you want to pass. Much of this is often times handled with some simple attributes on the elements themselves:
<a rel="foo" href="http://google.com">Google</a>
<a rel="bar" href="http://stackoverflow.com">Stack Overflow</a>
Which would use the rel
attribute as the "argument." You could access it from the $.click()
:
$("a").click(function(){
switch( $(this).attr("rel") ) {
case "foo":
// do x
break;
case "bar":
// do y
break;
}
});
As you could imagine, this could be extended to include attributes like:
rel="foo,2,max"
Where the value of rel
will be .split()
within the click-method giving us an array of "arguments" to consider in our logic.
$("a").click(function(){
var arguments = $(this).attr("rel").split(",");
for (var i = 0; i < arguments.length; i++) {
alert(arguments[i]);
}
});