I'm new to JS, and this video was exactly what I was looking for, in terms of teaching me how to use the listeners on a JS file linked to my HTML file. Thank you for this, definitely subbing!
This is simply the best explination I have seen for this part of javascript, one quesion: why do you use var image and not let image in index.html ? Thank you very much!
I have got a question... could someone please tell me what 'this' means inboth cases it is used. example.: this.width example.: onclick = "handleClick(this)"
For anyone watching using classes in stead of ID in your html, this is what you have to do for event listeners: var something = document.getElemtsByClassName("class-name"); for (var temp = 0; temp < something.length; temp++){ let someVar = something[temp]; someVar.addEventListener(THIS WILL WORK) }
4 года назад
fuck off nigga, why you need a 'for loop' over here
From an organization perspective , what do you recommend, to add all event listeners in your html page inline, or have your html and styling seperate, and then have your JavaScript file specifically for adding event listeners and handle user interaction
I'm having some trouble with the addEventListener section (around 7 to 9 minutes in). Here's my code, which I've copied from the video several times and tried in both Safari and Chrome, but the image doesn't pop out at all: function handleClick(element){ element.style = "background-color:blue;" } var image = document.getElementById("image"); image.addEventListener("mouseover", function(){ this.style ="box-shadow: 2px 2px 2px grey"; this.width ="110" }); The "image." and "this." both appear white in my .js document, not red as in Mike's. Any advice on how I can make this work?
So with the image, you do mouse out to set the image back…. But for the button, what event listener would I use to set the button back to its original state 😞 help someone please
for those who are having trouble with the code in the video for mouseover and out effect can try the code below, its much more simple in my opinion . function bigImg(x){ x.style.height="150px"; x.style.width="150px"; } function nrmlImg(x){ x.style.height="100px"; x.style.width="100px"; }