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

211
Views
Prevent default on screen, but allow buttons to be pressed

I'm building a website in js/html/css. To play part of my game the user needs to press and hold the screen. This will default to highlighting the play area, so on click or touch events I want to use an event.preventdefault(). The problem then is that the user can not click on other buttons on the page.

Is there a way to both prevent default when clicking and holding, but also allow buttons to work as normal?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

I think something like this might work. Basically using a boolean variable to detect if an specific button has been clicked and then add a conditional statement to the e.preventDefault() so when the button is clicked is not affected by the e.preventDefault()

let isClicked = false

document.getElementById('myBtn').addEventListener('click', () => {
   isClicked = true
   
   setTimeOut(() => {
      isClicked = false 
   }, 100)    
})

function myPreventDefaultFunction(e){
   if(isClicked){
     // do something 
   } 
   else{
     e.preventDefault() 
   }
}

about 4 years ago · Santiago Gelvez 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!