Is it possible to pass arguments to click or submit function like :
$("#example").click(function()
{
var myVar = x; // refering to x as passed argument
});
Maybe function inside a function ?
function Func(){
$("#example").click(function()
{
var myVar = x;
});
}
Maybe something like calling Func()('33'); will this pass the 33 to the click function, is it possible after all?
Without knowing what you want to accomplish, its hard to tell you what to do. Many times when a similar need arrises, it has to do with passing an ID to the function. There are a few ways to handle this, but lets look at one:
Now, if you click the first
ait alertsapple, the secondorange, and the thirdgrape. By declaring a variable in the function scope usingvarallows that particular click to know the correct value.Demo of this working