Mona Coder
Mona Coder

Reputation: 6316

Still Confused Between Event and Event Handlers in jQuery

Can someone please help me to understand what exactly is the "Event" and "Event handler" in following examples? According to www.w3schools.com here is the list of some common events

enter image description here

so why some people still keep saying Click event handler? is Click event or event handler?

1.

$( "p" ).click(function() {
       alert("Which One is Event and which one Event Handler");
});
$("p").on("click",function(){
       alert("Which One is Event and which one Event Handler");
});
$("p").css("background-color","yellow");

Upvotes: 0

Views: 61

Answers (2)

lante
lante

Reputation: 7336

Following your code:

$("p").click(function() {
    // this function is the event handler of the "click" event
});

which is the same as:

$("p").on("click",function(){
   alert("Which One is Event and which one Event Handler");
});

(see jQuery on documentation)

The following code, is not an event, just changes the style of the p elements:

$("p").css("background-color", "yellow");

Upvotes: 2

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114347

The event is the action. The handler is the receiver of that action, usually a function.

Upvotes: 6

Related Questions