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

854
Views
Safari: focus event doesn't work on button element

The focus event works fine on all browsers but Safari when it has been clicked.

And it works fine on div[tabindex] element, but don't work on button or input:button element.

It also can get the focus event when I use $('.btn').focus().

Why does the focus event haven't triggered on click ?

Here is my code:

$(".btn").focus(function (e) {
	$(".result").append("<p>Event:"+e.type+", target:"+e.target+"</p>");
})
.result{min-height:200px;border:1px solid #000;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button class="btn">button 1</button>
<input type="button" class="btn" value="button 2"/>
<div class="btn" tabindex="0">div element</div>
<h1>
Result:
</h1>
<div class="result">

</div>

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Documentation tells is not supported: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus

enter image description here

over 4 years ago · Santiago Trujillo Report

0

Why does the focus event haven't triggered on click ?

We found through research that Safari and FireFox on Macs do not set focus on buttons when you click on them.

The way we fixed that was to add a click listener to our buttons and call focus() on the button that was clicked.

In Angular it looked like this:

<button (click)="myClickFunction(); $event.target.focus();>My Button</button>
over 4 years ago · Santiago Trujillo Report

0

See https://bugs.webkit.org/show_bug.cgi?id=13724

This is working as intended on MacOS. Clicking a button, radio button, or checkbox doesn't give the element focus- thus it can't lose focus and trigger a blur.

The solution is to give it a click event that gives the element focus.

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!