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

266
Views
How to delete all "hidden" attributes from elements with same prefix using javascript?

Let's say, I've got something like this:

<div id="some_id">
    <img src="url1" id="el_id1" hidden>
    <img src="url2" id="el_id2" hidden>
    <img src="url3" id="el_id3" hidden>
</div>

And now, I need javascript to delete all this "hidden" attributes. I don't know the exact ids, I just know they all begins with prefixes of "el_id". How can I realize it using pure javascript?

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

0

So use attribute starts with selector and removeAttribute

var elems = document.querySelectorAll('img[id^="el_"][hidden]');
elems.forEach(function(elem) {
  elem.removeAttribute("hidden");
});
[hidden] { display: none; }
<div id="some_id">
    <img src="url1" id="el_id1" hidden>
    <img src="url2" id="el_id2" hidden>
    <img src="url3" id="el_id3" hidden>
</div>

about 4 years ago · Juan Pablo Isaza Report

0

Use document.querySelectorAll with a selector that:

  • Selects all <img> inside <div>
  • Which have an id starting with el_
  • Which have the hidden attribute

Remove hidden from the found elements using removeAttribute()

document.querySelectorAll('div > img[id ^= "el_"][hidden]').forEach(e => e.removeAttribute("hidden"));
<div id="some_id">
    <img src="url1" id="el_id1" hidden>
    <img src="url2" id="el_id2" hidden>
    <img src="url3" id="el_id3" hidden>
    <img src="url3" id="dontdelete">
</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!