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

168
Views
mouseenter doesn't get fired first time

When i go to part where the mouseenter is it doesn't get fired first time. But if i leave it and return and to the same part, then the mouseenter gets fired. I been desperately looking for a solution. The code part looks like this

if(target.hasClass("level1")) {
                    console.log(target);
                        target.mouseenter(function () {
                            newThis.focus(event, target);
                            timer = setTimeout(function () {
                                newThis.focus(event, target);
                            }, 200);
                        }).mouseleave(function () {
                            clearTimeout(timer);
                        });
                }

So yeah, the code works, but it doesnt get fired the first time.

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

0

That's intentional: it only fires on crossing the boundary upon entering.

Does the mouseover event solve your problem?

about 4 years ago · Juan Pablo Isaza Report

0

You are creating the .mouseenter and .mouseleave handler within an if. So once the if statement is fullfilled you set mouse enter/leave handlers. This means the events will only fire after the if was executed. So another mouse movement is required to trigger the newly added event.

You will typically create the handlers when loading the page and filtering inappropriate calls later.

Without knowing further context - try a concept where you don't need the if.
See example below.

let timer;

$('.level1')
.mouseenter(function (event) {
    var newThis = $(this).find('input');
    newThis.focus();
    timer = setTimeout(function () {
        newThis.focus();
    }, 200);
}).mouseleave(function () {
    clearTimeout(timer);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<html>
<body>
  <article>
    <section>
      <h1>Hello.</h1>
      <p>Article Text</p>
    </section>
    <section>
      <form>
        <div class="level1">
          <input type="text" name="one" />
        </div>
        <div class="level2">
          <input type="text" name="two" />
        </div>
      </form>
    </section>
  </article>
</body>
</html>

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!