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

128
Views
Modify user selection on click event on an <a> element?

When I click on the text in the div element i am able to modify the selection. However this is not possible with a link element. Is there a way I can make this work without modifying the html?

document.addEventListener('click', click, true)

function click(e) {
  e.preventDefault()
}

setInterval(() => {
  let selection = window.getSelection();
  selection.modify('extend', 'forward', "documentboundary");
}, 100);
<div>text in div tag</div>
<a href="">text in a tag</a>

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

0

Does this work?

document.addEventListener('click', click, true)

function click(e) {
  e.preventDefault()
}

setInterval(() => {
  let selection = window.getSelection();
  selection.modify('extend', 'forward', "documentboundary");
}, 100);
a {
  user-select: text;
}
<div>text in div tag</div>
<a href="">text in a tag</a>

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!