Jump to content

jQuery Function Parameter


terryds

Recommended Posts

// Create a value for the notice variable
var notice = "I live in a variable!";
$("p.foo").bind("click", { n:notice }, function(event){
console.log(event.data.n);
});
Look at the function(event) ! Where does the parameter event come from ? I don't understand... Is it a special parameter ?
Please explain me about the parameter.... And, i don't understand what { n:notice } means .... Can you tell me what's that ?
I don't understand why the result is "I live in a variable" ?
I'm also confused with the parameter of this function below... Are they special parameters too ?
$("p,.foo").map(function(index, ele){
$(this).append(" "+ele.tagName+" #"+index);
});

 

Link to comment
Share on other sites

Read this:

 

http://w3schools.invisionzone.com/index.php?showtopic=48339

 

 

 

And, i don't understand what { n:notice } means

That creates an object with a property called n, with the value of whatever the notice variable has.

 

 

 

I don't understand why the result is "I live in a variable" ?

The properties of the object get added to the data property of the event object. So the notice variable has that text in it, which gets assigned to a property called n of the new object, which gets added to event.data, so event.data.n contains the text.

 

 

 

Are they special parameters too ?

What is a "special parameter"? If you look at the documentation for the jQuery map method you will see that it gets passed a function, and that it will pass that function 2 parameters.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...