0

I Have multiple dom elements with same classname , i want to select all elements and using forEach function i want to add click event listener to it.

In vanilla javascript we select all elements using querySelectorAll

classname.forEach((e) => {
  e.addEventListener('click', () => {
    //logic
  }
}) 

how to do same as above using vue js?

3
  • stackoverflow.com/a/51021808/5252522 Commented Sep 6, 2022 at 5:23
  • You can use a query selector to get all the elements with the class name, and then this forloop that you have should work fine Commented Sep 6, 2022 at 5:34
  • You should probably use template refs rather than a query selector tho. Commented Sep 6, 2022 at 6:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.