Simple Javascript Events Tutorial with code! Almost every Web Developer finds themselves needing to respond to user actions on a page by changing content or adjusting the page display somehow. The way you do that is by listening to Javascript events.
VIEW THE CODE:
– addition: http://codepen.io/anon/pen/vOeeqG?editors=101
– pic link: http://codepen.io/anon/pen/vxYxKN?editors=101
Popular Javascript Events Are:
– click
– mouseenter
– mouseleave
– mousedown
– mouseup
– mousemove
– keydown
– keyup
– blur
– focus
See list of all javascript events here: https://developer.mozilla.org/en-US/docs/Web/Events
In this lesson, we’ll add event listeners to html elements. When the users click, focus, blur, press a key, or move their mouse, javascript will get notified and we can make the webpage change.
Listening to Javascript events is a bread and butter task for web development and web developers.
Amazon Auto Links: No products found.
Oh, just watch tutorial video offline, so forget to consult to source code. A little bit confused.
I need to watch it over and over again. 🙂 thanks
Even for android please
Example touchmove, touchatart.
Please
i got the complete video….all your tutorials are awesome…!!
i am just having problem with linking script files…help…!!
This video is helpful
1500th like! Great tutorial.
I was messing around with my script and wandering why it doesnt work, finally realized that I didnt linked it with HTML
Love your vids
17:30, got one question, in the for loop you said that *ALL IMAGES* will have a class of hide, but what if you just want to target, for example 3 images in your html, to have a class of hide, how will you do this?
7:50 Correct. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
How do you make the events.js file run constantly? when I put it at the top of the body it runs once and won’t allow for button events for happen.
Awesome tutorials. Thanks for the help!
Best to learn basics of events….
I thought when you put something in between quotes, it is just a word. But in this video, when it says things like mouseenter and mouseleave, they are like commands. Why?
it does’t work with local source images like src=”img/pic1.jpg”
hey can u elaborate on data-img…..plz……btw great work……its fun learning……but data-img
Hi LearnCode.academy/ anyone here,
Do you know why we need to use allImages to hide in the JS though css hide the images beforehand?
got a problem cannot-read-property-addeventlistener-of-null even i copy your code.
https://www.youtube.com/watch?v=arX4mTMSpco
Great tutorial, man! One question: why do you first bind the functions to events and THEN define the functions? I have seen this is common practice, but WHY? Thank you!
For some reason, my code isn’t working. Can you help me out here:
//index.html file
< !DOCTYPE html>
Addition of Numbers
+
//events.js file
var numTwo=document.getElementById(“numone”);
var numOne=document.getElementById(“numtwo”);
var addSum=document.getElementById(“addsum”);
numOne.addEventListener(“input”,add);
numTwo.addEventListener(“input”,add);
function add(){
var one = parseFloat(numOne.value)||0;
var two = parse(numTwo.value)||0;
addSum.innerHTML=”your sum is: ” + (one+two);
}
really very helpful thank u 🙂
Thanks a lot from India..
Pls help:
I did the second part for image hide and show with same names and elements, but at event listener it gave me this message (Uncaught TypeError: Cannot read property ‘addEventListener’ of null).
Thank you
which event are basic events and which events are standard event please reply fast and tell me the difference tooo
This is an excellent video but I seem to have a problem with the HTML. I didn’t get more than a glimpse at the code used. Mine nearly works except that this section of code is rendered in the browser:
wikimedia.org/wikipedia/commons/a/aa/
Simon_Cowell_in_December_2011.jpg”
wikimedia.org/wikipedia/commons/0/00/
Bruce_Willis_by_Gage_Skidmore.jpg”
carsonscholars.org/files/imce/bccurrent.jpg” alt=””
(except that the
tags don’t appear.)
That didn’t bother me much except that what was causing that seems to have prevented me from getting past 15:56. I can console.log(picId) correctly but I get
“Uncaught TypeError: Cannot read property ‘className’ of null
at HTMLAnchorElement.picLink” at the line:
var pic = document.getElementById(picId);
Is this because of the HTML inadequacies?
Excellent tutorial. Thank you
How to make a bar line???
When you learn more in a couple videos than you did in 3 years of Uni 😐
Total noob question here about the DOM. What exactly does document.getElementById() mean? Code in an external JS file like:
var x = 10;
document.getElementById(“p1”).inner HTML = x; (and the p element containing the ID in the HTML) doesn’t technically have anything to do with the p element, right? I mean, the JS is external code and is just about a variable definition. Is the fact of displaying the variables value on the web page the only reason for why this method is required? There is other JS code that is going to display, output something to the web page, and doesn’t require this obeject.method. I find myself writing some functions in external JS files and I can’t get them to work until I define an ID in the HTML and pass it into this object.method. Is this used only for any kind of scripting that will do something on/to the web page, or is there another purpose/meaning in using this object.method? Thank you. =)
two questions about your sublime setup:
1. what color scheme are you using?
2. how do you make var and function keywords italic?
kindly help me….
Uncaught TypeError: Cannot read property ‘addEventListener’ of null
what is the solution for this error other than adding script at end of page as i already did that and still having this error :'(
how do i access you’re jquery tutorial?
damn this is complicated
You are amazing sir. i know what I will be doing in my summer break. Learning java script from you!
Your tutorials are great!
i dont understand what does it do??
pic.className = “”;
didnt work for me
I watched all the videos up to here and I still don’t get how to make the exact same look of a web page like you did … I get it that the point here is to teach us how js works to user input, but how can I perform that if I don’t know how to make it look like that
can i use href instead of data-img? like href=”#simon-pic” and id of img as img=”simon-pic”?
is it sublime text in the video ? What theme is that ? I want it!
I know this is not about this video but what color scheme are you using?? You *MUST* reply, please!