Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

2.7K
Views
Vue2 how to use $refs to target an element and remove css class

I want to remove the css class of an element when a method is called. but I want to do this using $refs.

template:

  <div class="modal"  ref="myModal"></div>

method:

      closeDropdown: function() {
            this.$refs.myModal.$el.removeClass("open");
      }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

this.$refs.myModal.classList.remove("open");
over 4 years ago · Santiago Trujillo Report

0

Two steps:

  1. const modalElement = this.$refs.myModal; // reference to the DOM element
  2. modalElement.classList.toggle("custom"); // use classList API of DOM element

classList API reference: https://developer.mozilla.org/en-US/docs/Web/API/Element/classList, you can use this API to modify its classes using the add(), remove(), replace(), and toggle() methods.

You can also refer to this CodeSandbox Vuejs example: https://codesandbox.io/s/nervous-wood-s3nhq?file=/src/App.vue:269-481

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!