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

193
Views
Why people are using getElementById instead of accessing elements directly?

In every single tutorial I have seen that using document.getElementById(id); is recommended, but it's longer than just accessing the elements directly by their IDs. Example code that is perfectly functional:

<script>
    function appendText() {
        foo.innerHTML += bar.value
    }
</script
<div>
    <p id="foo"></p>
    <input type="text" id="bar" />
    <button onclick="appendText()">Add</button> 
</div>

What are disadvantages of accessing elements like that, and why nobody is using it that way? For me it was always more handy to do this that way. Or maybe people just don't know that there is such a possibility?

about 4 years ago · Juan Pablo Isaza
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!