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

93
Views
Can i trigger browser to focus element in JS

When i want to focus on some element I use focus() function which gave me :focus from css. The thing is that when i am focusing with TAB keyboard button i get that styling from css but also some blue styling around element which is probably some browser focus. Can I trigger that blue browser focus somehow too with js?

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

0

You can override this with the focus-visible CSS. Adding sample working example below for reference

button {
  background: #F0FF00;
  border: 1px solid #ccc;
  font-size: 18px;
}

.clear-focus {
  background: #00FF00;
}

.clear-focus:focus-visible, .clear-focus:focus  {
  outline: none;
  box-shadow: 0px 1px 6px 0px #000;
}
<input placeholder="click to focus here manually" type="text" />

<p>Now press tab</p>
<button >Button without focus override / default focuss css</button>


<p>Now press tab agian</p>
<button class="clear-focus">Override focuss css /  with custom css</button>

isible` CSS class. Sample code below:

about 4 years ago · Juan Pablo Isaza Report

0

we can use outline: none;,it hides outline

:not(.focusable){
  outline: none;
}
<input placeholder="You can't focus me*" type="text" />

<p>press tab</p>

<button class="focusable">You can focus me</button>
<button >You can't focus me*</button>

<p>again repeat</p>

<input placeholder="You can't focus me*" type="text" />

<p>press tab</p>

<button class="focusable">You can focus me</button>
<button >You can't focus me*</button>


<p>*Focus is possible to all element,but border is only hided,as per OP's question</p>

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!