1 Javascript Events Wed Apr 04, 2012 1:18 am
Mr.Joker
Mr. WebArtz
JavaScript Events Quick Links for all the Tutorials at WebArtz |
Hello again, I am Mr.Joker and today I will teach you what are events. I allready spoken about events when I talked about functions but lets pass trought that again. A function is a massive code that contain different activites. I used example with jumping. A function for jumping would be, squat, and jump. Thats two actions in one function. But event is when will that function be preformed. When a teacher tell you "jump" thats an event, he activate the function by telling you to do it when he want. Its the same with javascript. There are 4 most used events (onLoad, onClick, onMouseOver, onMouseOut). Each have different way to apply function. Lets pass trough each of them.
Here we have a function that have variable x with value 5, and that variable will be displayed. But when? In body tag we have some paragraph with number 4, and there I added an event as you can see. onMouseOver="test()" activate the function when someone pass mouse over paragraph. And thats true. If you test code it will happend for real. When we can use both of them, like onMouseOver and onMouseOut. Well we can with image like this: DEMO HERE But when you look at the code:
Its too much complicated to explain you now because I yet didnt explained nthing about Arrays. So we will just pass this part and will explain you when we learn arrays. onLoad is used when page loads and its simple:
We have a function and inside it a variable x with value of 4. A function should write that number on screen but it will nto happend if we dont use event. I used event inside body tag (onLoad) and thats why function will work. And last example is on click. We will use it for links (just an example).
Now we have a link on our page, and as soon as someone click on link an event as onClick will activate a function called test. And an alert box will appear. Its all you need to know about events. |
Notice : These tutorials are copyrighted by WebArtz Forum. You may not publish it on anywhere without written permission from the administrators. |