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

103
Views
JavaScript bookmarklets don't modify the correct document.activeElement?

I am trying to use a bookmarklet to modify the content of the currently-active textbox.

If I write let a = document.activeElement; console.log(a), then in my console, I see the currently-active textbox correctly printed to the console. If, in the console, I then write a.value = "hello", the content of that textbox changes exactly as expected.

If I write let a = document.activeElement; a.value = "hello" in my bookmarklet, however, it replaces the entire document with the text node "hello." Same with document.activeElement = "hello".

I am guessing that once the bookmarklet is clicked, the entire document or browser window becomes the activeElement. But if that's true, I'm not sure why the correct node would be referenced and preserved in the first case. Nor can I find any way to preserve the reference to do anything with outside of the console.

Is it possible to do this?

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

0

I'm not sure it's possible to detect focus after it has been changed, in this case, by clicking the bookmarklet. Although more annoying, you could check for focus changes with the onfocus event, and only then use document.activeElement.

MDN Docs — onfocus

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!