Converting jQuery To Vanilla JavaScript | Click Event

Опубликовано: 29 Сентябрь 2024
на канале: Brian Love
245
4

In this video, I am going to walk you through the process of converting a jQuery snippet into Vanilla JavaScript

We're going to create two variables (const) that we can use to select the elements on our page. In this example, since I only have one instance of -form-btn and custom-btn, I'll use document.querySelector

We'll then attach an event listener to the customBtn variable. The event listener is listening for a click event on the element we stored in the customBtn variable.

Inside the event listener function (inside the curly braces), we'll click on the form-btn element using formBtn.click()

This will click on the form-btn every time we click on the custom-btn