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

98
Views
How to add instance of javascript Class in a DOM element

I need to expose the istance of a class to be called from the dom element.

i've created a class that i'll instance as new myCustomClass(). This class is related to a DOM element.

What i need to do in my class to access to his methods and property form the dom?

I need something like this (this is something that swiper.js do)

var foo = document.querySelector('.element-where-class-is-instanced').myCustomClass;
foo.init()

thanks to all

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just assign the class instance to the element property earlier:

document.querySelector('.element-where-class-is-instanced').myCustomClass = new myCustomClass();
about 4 years ago · Juan Pablo Isaza 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!