hello guys welcome to the next blog on JavaScript tutorial for beginners in this blog we will learn how to use events in JavaScript so first of all what is an event an event can be an action which is performed to do some work for example you click some button you hover over some HTML element or you press some key right so let's see how we can use events in JavaScript so for example I will create a button element here and I add our text here and as an attribute of this button I will add an event called on click ok so on click is an event and when this button is clicked I want to perform some action for example I want to alert something right now keep in mind here we are using single code inside a lot for example hello world and I think you may understood this because we are including alert in double quotes and if you use double quotes here it will be not escaped and it will create some problem ok so let's save our code and refresh our webpage and you see this button and when you click this button it will show you this message called hello world right now for example I will create one more item here for example it is a h1 tag and the ID of this h1 tag is for example my ID okay and instead of using this I can use this method in JavaScript which is called get element by ID and give your name of your ID which is my ID and keep in mind just add this ID in single quotes here right then dot inner HTML there is a method in JavaScript called date and this returns current date and time okay so save your code and refresh your webpage and once you click this button it's going to give you the current date and time with timezone here also now there can be different type of event which are possible and most common events are these so on click we have already used for example let's say we are using on mouse-over okay so instead of one click let's paste on mouse over here save your code and refresh our page and when you hover over your button not click but hover over and it will show you the result and once again when you hover it will refresh the time right you see it's refreshing the time in second okay now instead of using this JavaScript functionality here you can use a JavaScript function so just add a JavaScript function like this in the script tag make a function called Show and what it does is it's doing the same job as this code okay so I'm going to remove this code from here and instead of this code I can call this JavaScript function right save your code and refresh your webpage and when you hover over your mouse once again you see the same result now for example you want to show this time on this button itself what you can do you can do something like this so just copy this inner HTML is equal to date and just write this dot inner HTML is equal to date and save your code and refresh it and when you hover over it it will show the date on your button okay so you can do this also now to use this on load event what you can do is you can go to your body element and call this onload event is equal to the function for example we want to perform this function okay so do this and then you can remove this button because we don't need it right now and save your code and once you refresh your code it will show you this date and time when your body element loads now to use this on keydown event what you can do here is instead of a button you can use our input and this input can be of type text and then you can call this on keydown event here and you can call this function to your own keydown event so like this okay and save your code and refresh your page and then it will show you this right so whenever you enter something in this input box then your time will change right you can see here okay now we must remove this from here in order to understand it clearly so once again refresh our page and whenever you enter something it refreshes your time okay so in this way you can use these events in JavaScript I hope you have enjoyed this blog