Main

Introduction to Browser Events | JavaScript Tutorial in Hindi #47

Link to the Repl - https://replit.com/@codewithharry/47Events Join Replit - https://join.replit.com/CodeWithHarry Download Notes - https://www.codewithharry.com/notes/ Ultimate JS Course Playlist: https://www.youtube.com/playlist?list=PLu0W_9lII9ahR1blWXxgSlL4y9iQBnLpR ►Checkout my English channel here: https://www.youtube.com/channel/UC7btqG2Ww0_2LwuQxpvo2HQ ►Instagram: www.instagram.com/codewithharry python, C, C++, Java, JavaScript and Other Cheetsheets [++]: Playlist: https://www.youtube.com/playlist?list=PLu0W_9lII9agrsRZjFECeFuWY5ev2pQlk ►Learn in One Video[++]: Python[15 Hr]: https://www.youtube.com/watch?v=gfDE2a7MKjA&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 Python Advance[3.5 Hr]: https://www.youtube.com/watch?v=61a7UkDO50s&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 Python[1 Hr]: https://www.youtube.com/watch?v=qHJjMvHLJdg&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 Python[2 Hr]: https://www.youtube.com/watch?v=ihk_Xglr164&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 Python[15 Min]:https://www.youtube.com/watch?v=fr1f84rg4Nw&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 JavaScript[1 Hr]: https://www.youtube.com/watch?v=onbBV0uFVpo&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 C[1.3 Hr]-https://www.youtube.com/watch?v=YXcgD8hRHYY&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 php[1 Hr]: https://www.youtube.com/watch?v=xW7ro3lwaCI&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 php[2.3 Hr]:https://www.youtube.com/watch?v=1SnPKhCdlsU&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 php[Project]- https://www.youtube.com/watch?v=-al2bECumKg&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 HTML[30 Min]:https://www.youtube.com/watch?v=E3ByCRqE7Lo&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 CSS[8.5 Hr]:https://www.youtube.com/watch?v=Edsxf_NBFrw&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 CSS[1.4 Hr]:https://www.youtube.com/watch?v=u5-K_ua9sOw&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 Wordpress[3.2 Hr]:https://www.youtube.com/watch?v=GlLRYml8mCY&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 Angular[2 Hr]:https://www.youtube.com/watch?v=0LhBvp8qpro&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 Java[2.3 Hr]:https://www.youtube.com/watch?v=rV_3Lewxx6o&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 Web Scraping[1 Hr]:https://www.youtube.com/watch?v=uufDGjTuq34&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 MongoDB[2 Hr]:https://www.youtube.com/watch?v=oSIv-E60NiU&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 Numpy[1 Hr]:https://www.youtube.com/watch?v=Rbh1rieb3zc&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 Android Dev[12 Hr]- https://www.youtube.com/watch?v=mXjZQX3UzOs Linux[1 Hr]:https://www.youtube.com/watch?v=_tCY-c-sPZc&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 JQuery[1.1 Hr]:https://www.youtube.com/watch?v=YFlx1C8XwR0&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 Git and GitHub[1.1 Hr]:https://www.youtube.com/watch?v=gwWKnnCMQ5c&list=PLu0W_9lII9ahKZ42vg2w9ERPmShYbYAB7 ►Complete course [playlist]: React: https://www.youtube.com/playlist?list=PLu0W_9lII9agx66oZnT6IyhcMIbUMNMdt Python-https://www.youtube.com/playlist?list=PLu0W_9lII9agICnT8t4iYVSZ3eykIAOME OOP Python-https://www.youtube.com/playlist?list=PLu0W_9lII9ahfRrhFcoB-4lpp9YaBmdCP Java:https://www.youtube.com/playlist?list=PLu0W_9lII9agS67Uits0UnJyrYiXhDS6q JavaScript- https://www.youtube.com/playlist?list=PLu0W_9lII9ajyk081To1Cbt2eI5913SsL PHP-https://www.youtube.com/playlist?list=PLu0W_9lII9aikXkRE0WxDt1vozo3hnmtR C-https://www.youtube.com/playlist?list=PLu0W_9lII9aiXlHcLx-mDH1Qul38wD3aR C++-https://www.youtube.com/playlist?list=PLu0W_9lII9agpFUAlPFe_VNSlXW5uE0YL Git & GitHub-https://www.youtube.com/playlist?list=PLu0W_9lII9ahVQekD7ePHmnirTePXwIln Android Dev- https://www.youtube.com/playlist?list=PLu0W_9lII9aiL0kysYlfSOUgY5rNlOhUd Python GUI- https://www.youtube.com/playlist?list=PLu0W_9lII9ajLcqRcj4PoEihkukF_OTzA Web Development- https://www.youtube.com/playlist?list=PLu0W_9lII9agiCUZYRsvtGTXdxkzPyItg Python Django:https://www.youtube.com/playlist?list=PLu0W_9lII9ah7DDtYtflgwMwpT3xmjXY9 Projects Using HTML, CSS & Javascript- https://www.youtube.com/playlist?list=PLu0W_9lII9aiQiOwthuSvinxoflmhRxM3 Data Structure and Algo:https://www.youtube.com/playlist?list=PLu0W_9lII9ahIappRPN0MCAgtOu3lQjQi Follow Me On Social Media ►Website (created using Django Rest & Angular): https://www.codewithharry.com ►Facebook: https://www.facebook.com/CodeWithHarry ►Instagram: https://www.instagram.com/codewithharry/ Twitter: https://twitter.com/CodeWithHarry Comment "#HarryBhai" if you read this 😉😉

CodeWithHarry

1 year ago

In today's video we are going to understand how browser events work. We'll also see what are the methods used to handle browser methods. Which methods we should use. Let's get back to the computer screen. Let's get started. [ MUSIC 🎶 ] So guys I've created a repl here and in it I have created something to explain you about events. And I want to tell you that if you do anything in the browser. Let's say you click on the mouse or you move the mouse around. Then an event is generated. Now if I tal
k about what is an event, It is a signal that something has happened. Like a wedding in your neighbourhood is said to be an event. Let's say if there is someone's birthday or someone falls while walking. That is also an event. Or someone is eating food that is also an event. So birthday, wedding, someone's falling, a dog biting a person. All of these are recognised as events. So now let's talk about DOM events which I think will be a new concept for you guys. For example, DOM events like mouse e
vents, keyboard events, form element events. And document events. Now you will think everything was going great in JavaScript. What are the events? If you click anywhere in the browser then a click event is generated. And you will want to handle that particular event. Now I'll write here events. And I will do one more thing over here. I will write here . And after that I’ll create a button in it. Now if I write here onClick=”alert(‘hello’)” I've already used double quote in here that’s why I’ll
use single quote now. Then what will happen is. Let's say I will write this or even better I’ll write click me. Now when reload the page it's title will change to event and. When I click on the button it will display an alert “hello”. This means if you click on this button then. This particular JavaScript will get executed. Can I write more JavaScript code in this? Can I do something like this? Let a = 6; And let's say after that I’ll console. log(a) Can I do something like this? Now if I write
some JavaScript like this will it run? This is the question and let's find out the answer to this question. I'll tell you before only that this will work. This JavaScript will run. Now if I click on the button it will display an alert "hello". And 6 will be printed in the console because I printed it. With the help of console.log(a). Now the main problem is that you cannot write this much JavaScript in here. It is possible but not maintainable and also it will not look so good. And the solution
to this problem is. What we’ll do is instead of doing this. We’ll look at one more method to handle events. Let's quickly get back to the notes and consolidate all the knowledge. An event is a signal that something has happened. All the DOM nodes generate such signal. Now if you hover your mouse over a box, that is an event. If you move away the mouse away from the box or click it. Then that is also an event. If you release the click that is also an event. If you move the mouse that is also an e
vent. If you do contextMenu(right click) that is also an event. Keyboard events are: Key down, key Up. You press the key then key down and if you leave it then key up. Form element events are: When you submit a form or focus on an element. Form element event are submit, focus, etc. When your whole document loads then the document event domContentLoaded event pops up. Now we'll go back are our repl and see how these events work. So the first thing I'll do is that I'll assign an event to container
called onmouseenter. And on Mouse enter I'll write alert(‘container inside the mouse’) Like this. I’ll save and reload the page. And as I click on the button an alert will appear. “Mouse inside the container”. Alert will appear again and again when the mouse enters the container. Let's say I change this to console. log. Then I will get the message in the console. Now, let's say I'll write onClick = console. log. And inside that I will write. "Click happened in the container' I’ll reload the pag
e. The page is loaded now. And now when hover the mouse over the container it prints. "Mouse inside the container" in the console. And if I click on the container "click happened on the container". Will be printed in the console. It is very simple. I've also written in my notes also that. Event can be handled through HTML attributes. Input value = “hey”. And when we click, then the JavaScript inside onClick will be executed. And if you write onmouseenter then, when the mouse enters. Then the Jav
aScript inside onmouseenter will be executed. Don't put double quote inside other double quote because it will cause problem. Let's assume if you want to run a function or functions in JavaScript. Or a Script with 15-20 lines of code. How you will do that? I'll explain you that in the upcoming videos. Before that I will show you one more method to handle events. Which solves this problem to a certain extent. But then also a problem remains. What is that? I'll tell you now. So the first thing is
that you can easily handle an event using onClick. Which means instead of writing all these attributes. You can write here that the container which is document. getElementsByClassName document. getElementsByClassName document. getElementsByClassName("container") Not .innerHTML. Let's say if you write. Click home. Let a = document. getElementsByClassName('container')[0] And after that you write. Where does this " comes from again and again. Now, if you write a.onClick =. And you create a function
like this. I'll accept what the AI is suggesting. Let's say if I click this. First let me reload the page. Cannot set properties of undefined on onclick. Not ClassByName. I’ll have to correct it in both places. Now I will reload and if I click on this. Then it's HTML will change to hello world as I have written here. Have you noted one thing. I think I removed it from here. No, I didn't removed it. If I write onclick in both the places. Then the onclick in the JavaScript will be considered. It
will consider the onclick which is there in JavaScript. Now what we'll do is in the upcoming videos. Will understand other ways to handle events. We'll discuss about addEventListener and removeEventListener. I've also written a note here that adding a handler with JavaScript. Overwrites the existing handler. You can keep these attribute handlers but. If you bring attributes like this then these attributes. Will get overwritten in JavaScript I hope you understand how it's working. We’ll see more
things in the upcoming videos. Please access the JavaScript play-list and if you haven't. Accessed the notes yet, please access it. So that's it for this video. Thank you so much guys for watching the video. And I will see you next time. [ MUSIC 🎶 ]

Comments

@CodeWithHarry

Playlist access karein Dosto half century hone wali hai 😁😁 https://www.youtube.com/playlist?list=PLu0W_9lII9ahR1blWXxgSlL4y9iQBnLpR

@coderdoctor

Still Watching You I am Watching You For the Past 3 Years Thanks A lot for helping me

@Saniyakhan0729

I think I will become a complete web developer from you, Harry Bhai Thank you for make This course..🥰🥰🥰

@ameer_aley

Dum mast qalandar Ali Ali...!❤

@Why_me874

maine Angela yu se bhi JS padhi hai but harry bhai aap to gazab hi ho....

@notrushi

I think we can just call the function inside onClick and create a function in script.js it will be simple but harry is using DOM manipulation for this is there any specific reason for this ?

@lakshyarajdash

Harry bhai what's the solution of the setinterval quiz of JavaScript ?

@payalthakur6065

bhai mere pas windows 7 hai usme vs code and sublime text dono nhi chal pa raha hai pehle to vs code jb install Kiya tha tb 1 week sahi chal raha tha but fir live server chalna band hua or fir vs code open hi nhi ho raha ...... Same sublime chal raha hai pr uska Brower syn( live server ) nhi chal pa rha......

@sobiashabeer7107

The level of this course has gone up🔥 and it is becoming more interesting. This course is very helpful for me. Thank You Harry!

@monicabhattacharya9029

Thank you so much bro 👌👏👏👏👏👏👏👏👏👏👏

@souvickdas.

Harry bhai.. both the content and the editing are outstanding 😅😅

@priyanshutyagi_02001

Thankyou harry bhai❤

@ajeetverma3936

Thank you so much harry bhai...

@kinggamer-xv3kx

Harry bhai website ko proper launch Krna hai apki kon si video dekhu jisme hoisting bhi ho free mai

@shaikh8958

Thank u Harry bhaiya❤️

@kaverivishwanathkamble6507

Bhaiyya, Computer graphics ka course launch kijiye na plzzz...

@shrutishinde-md3rc

Best Example For Mouseenter is Amazons Product Image on right side whenever we hover over product image😲😲😲😲

@gopilalmewada6654

Thank sir video banane ka liye

@orbitxyz7867

Sandeep maheshwari sir k show mey kab jayengey sir🙂

@anuragnagar11

Harry Bhai Ajj Energy Kam Lag Rhi Brooo