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

216
Views
Why is class JS is executing twice?

In general, the problem is this. I create a class, write output to the console, and output the code twice. What to do?

import { CoreValid } from "./core.component"

export class Validator extends CoreValid {

  constructor(elementId, btn, dataName) {
    super(btn)
    this.$dataName = dataName
    this.$el = document.querySelector(elementId)
  }

  init() {
    this.$btn.addEventListener('click', this.haha.bind(this))
  }

  haha(event) {
    event.preventDefault()  
    console.log('one')
  }

}

And its main component

export class CoreValid {

  constructor(btn) {
    this.$btn = document.querySelector(btn)
    this.init()
    this.idCreate()
  }

  init() {}

  idCreate(){}

}

And this is screen

enter image description here

And this is HTML

                    <form action="">
                        <input type="text" class="main-input" placeholder="Title" data-nav="title" id="1" name="">
                        <div class="block-colors">
                            <input type="text" data-nav="color" placeholder="RGB" id="2">
                        </div>
                        <button class="submit">Submit</button>
                    </form>
about 4 years ago · Juan Pablo Isaza
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!