Jump to content

Event - function?


eduard

Recommended Posts

An event is something that changes the environment. Many events are caused by the user, like a click or mousemove event. Events also occur when the page stops loading, and when an image stops loading. A function is a set of instructions that get executed whenever the function is called. A function can be called when an event fires. For that to happen, your program must bind the function to the event. There are several ways to do that. You've probably seen this:

function sayHello () {   alert ("Hello");}document.getElementById("myButton").onclick = sayHello; // notice there are no (parentheses) used in the assignment

There are other ways to bind a function to an event. element.addEventListener is the W3C standard.

Edited by Deirdre's Dad
Link to comment
Share on other sites

Example of a function: function ave( x,y ) {var z = (x + y)/2;return z;} Once this function has been declared it can be used elsewhere. Your code can simply call it. var myAverage = ave( 33, 67 ); http://www.w3schools.com/js/js_functions.asp An event is something like a mouse-click or a mouse-over or a page-load. In order to monitor a particular event you assign it to a particular function which is then considered an "event handler function" for that event. http://www.w3schools.com/js/js_htmldom_events.asp

Link to comment
Share on other sites

An event is something that changes the environment. Many events are caused by the user, like a click or mousemove event. Events also occur when the page stops loading, and when an image stops loading. A function is a set of instructions that get executed whenever the function is called. A function can be called when an event fires. For that to happen, your program must bind the function to the event. There are several ways to do that. You've probably seen this:
function sayHello () {   alert ("Hello");}document.getElementById("myButton").onclick = sayHello; // notice there are no (parentheses) used in the assignment

There are other ways to bind a function to an event. element.addEventListener is the W3C standard.

Thanks very much!
Link to comment
Share on other sites

An event is something that changes the environment. Many events are caused by the user, like a click or mousemove event. Events also occur when the page stops loading, and when an image stops loading. A function is a set of instructions that get executed whenever the function is called. A function can be called when an event fires. For that to happen, your program must bind the function to the event. There are several ways to do that. You've probably seen this:
function sayHello () {   alert ("Hello");}document.getElementById("myButton").onclick = sayHello; // notice there are no (parentheses) used in the assignment

There are other ways to bind a function to an event. element.addEventListener is the W3C standard.

Thanks very much!
Link to comment
Share on other sites

Example of a function: function ave( x,y ) {var z = (x + y)/2;return z;} Once this function has been declared it can be used elsewhere. Your code can simply call it. var myAverage = ave( 33, 67 ); http://www.w3schools...s_functions.asp An event is something like a mouse-click or a mouse-over or a page-load. In order to monitor a particular event you assign it to a particular function which is then considered an "event handler function" for that event. http://www.w3schools...ldom_events.asp
Thanks very much!
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...