I am starting a new mini series on JavaScript. I’m starting it from zero. Anyone can start learning from here. My goal is helping others while learning! I know about JavaScript and I’m working on a MERN tech stack. But I think it is not a bad idea to revise the JavaScript from scratch and helping others in this time. If you have any questions, shoot on the comment session or you can directly ask me in my social media. Social media links are in the last part of today’s lesson! Let’s learn JavaScript together.

Dom Event Introduction— JavaScript Series — Part 27

A full series to learn the JavaScript from zero

Muhammad Ali
3 min readFeb 26, 2020

Events are things like — clicking, hovering on something or typing anything on search. There can be many others event in a website. We can do something based on this event using javascript

We’ll start playing just by using a button. Let’s add a button to the html. You can find the code in github

You can read more about events in mdn web docs

We are going to use a mouse event for today’s example

First we’ll get the button using document.querySelector('button')

Second step will be add a EventListener. Which is going to run the event. addEventListener has 2 parameters. One is the event name, another one is function where we are going to write what happens if the event occurs.

Let’s write some code now

See the result

Turn on the notification so that you can stay with me when I publish the next part of this!

Other posts of this series can be found here — https://blog.nerdjfpb.com/tag/javascript/

Originally it published on nerdjfpb blog. Check the git for codes.

you can connect with me in twitter, linkedin or instagram

--

--

Muhammad Ali
Muhammad Ali

Written by Muhammad Ali

An otaku who loves computer. Love to write and help others through my work. Have a look on my Instagram https://www.instagram.com/nerd_jfpb/

No responses yet