Question 1
I've just started learning jQuery and one thing that puzzles me is function()
with a parameter in it, ie: function(e)
.
[Example 1]
$("#rating a").click(function(e){
// stop normal link click
e.preventDefault();
}
What is e
in function(e)
?
[Example 2]
$.post("test.php", function(data) {
alert("Data Loaded: " + data);
});
How do you know what data
is? I assume data
is different from e
in example 1.
I'm confused as to why function()
is different in different senarios...
Question 2
Since we are talking about basic jQuery, here's another jQuery question. What is the difference between this
and $(this)
?
[Example 3]
$(document).ready(function() {
// use this to reset several forms at once
$("#reset").click(function() {
$("form").each(function() {
this.reset();
});
});
[Example 4]
$("a").hover(function(){
$(this).parents("p").addClass("highlight");
},function(){
$(this).parents("p").removeClass("highlight");
});
});