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

155
Views
multiple ids in one get element javascript

now, this is ugly, how do I put them together in 1 row

function side1() {
  document.getElementById('side-open1').classList.remove('side-open-dpn');
  document.getElementById('item-link1').classList.add('side-open-dpn');
  document.getElementById('item-link2').classList.add('side-open-dpn');
  document.getElementById('item-link3').classList.add('side-open-dpn');
  document.getElementById('item-link4').classList.add('side-open-dpn');
  document.getElementById('item-link5').classList.add('side-open-dpn');
}
function back1() {
  document.getElementById('side-open1').classList.add('side-open-dpn');
  document.getElementById('item-link1').classList.remove('side-open-dpn');
  document.getElementById('item-link2').classList.remove('side-open-dpn');
  document.getElementById('item-link3').classList.remove('side-open-dpn');
  document.getElementById('item-link4').classList.remove('side-open-dpn');
  document.getElementById('item-link5').classList.remove('side-open-dpn');
}

i want the item-link(1;5) to be selected together, tried querlySelectroAll too, but maybe i did someting wrong

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

0

You can pick them with their ids, sice all of their ids starts with item-link, you can use document.querySelectorAll("[id^='item-link']")

"[id^='item-link']" will select all elements whose id starts with item-link

const nodes = document.querySelectorAll("[id^='item-link']");
console.log(nodes);
<div id="item-link1"></div>
<div id="item-link2"></div>
<div id="item-link3"></div>
<div id="item-link4"></div>
<div id="item-link5"></div>

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!