Skip to content
Advertisement

Tag: dom-events

Why currentTarget value is null

I am learing event.target and event.currentTarget. I think i am clear with the difference between the two. But stuck in a situation where event.currentTarget value turns out to be null. Following are the HTML and JS code snippets: HTML code JavaScript Code My doubt is that in line1 and line3 I got the value of event.target the same. But there

How to remove event callback with parameters

I have a web application that page A has video, and page B doesn’t. The video has the onended event when it finishes video playback. I tried to remove the event before the component unmounts with removeEventListener, or the video ended event will be fired after I switched to page B. However, I cannot find the proper way to remove

Execute Javascript code on HTML button click

I’m currently making an eshop. I use cookies to store the shopping cart. This is my HTML button: And when the user clicks this button I want to execute the following Cart.js code, which simply creates a cookie and add the product id to cookie cart. My problem is that when I click the button it takes no action. What

How can I make a simple chat/store messages in localhost?

I’m working on exercise, a simple chat/store messages, working on localhost, but it’s not working properly. The objective is to send user and message, and store the user and messages sent with a date. Like:(11:32 @USER: Hello world). This message data (with user,message and date) should be displayed on page, one after another. I’m doing this with no dependencies, but

why my last.addEventListener(“click”,nextLevel) not working?

https://codepen.io/demi-chen/pen/RwGPgxv I try to find the lastElementChild in the first div. It does show …… after I use console.log to check. why the addEventListener not working. I click the lastElementChild smile.png face but it’s not working. if function nextLevel() is working. the left&right side should add more smile.png. Tks! Answer its quite a simple fix really change your nextlevel to

Alpine.js how to bind to DOM events with dots in the name

Using Alpine.js version 2.7.3, a component can listen to DOM events using x-on:[event].[modifiers]. But what syntax is used to listen to event names that have dots, like bootstrap’s show.bs.modal? In Vue.js, this can be done by a custom directive (from this question), but I think custom directives can not be created in Alpine.js Answer It’s not possible at the moment

Advertisement