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

114
Views
How to get the iframe style attribute value then update its parent element

This is the dynamic code that are generated and I can't control it.

<div class="iframe__wrapper">
    <iframe height="0" width="0" style="display: block; visibility: visible;" src=""></iframe>
</div>

This is what I want to achieve, using javascript. I want to get the iframe style attribute value, lets say if this style is 'display: block; visibility: visible;' then target its parent class of 'iframe__wrapper' and overwrite its styles.

I dont want to target directly the class 'iframe__wrapper' to update its styles because that class is used in other pages.

And I'm having some problems using getElementsByTagName it says Uncaught TypeError.

Notes: There are other iframe inside the body content, so I think getElementsByTagName is not the right method? The iframe generated code with that style value sometimes appeared inside the head tag, sometimes inside the body tag or even inside the html tag.

You can change/update my code in the simplest way.

Below is my code and you can also check it here https://codesandbox.io/

const myIframe = document.getElementsByTagName("iframe");
if (myIframe) {
  myIframe.style.cssText = `
  display: block; 
  visibility: visible;
`;
}
const parentDiv = myIframe.parentElement.className += ' iframe__wrapper--updated';
.iframe__wrapper {
  padding: 100px;
  margin: 100px;
}

.iframe__wrapper--updated {
  padding: 0;
  margin: 0;
}
<div class="iframe__wrapper">
  <iframe style="display: block; visibility: visible;"
    title="Inline Frame Example"
    width="300"
    height="200"
    src="https://www.openstreetmap.org/export/embed.html?bbox=-0.004017949104309083%2C51.47612752641776%2C0.00030577182769775396%2C51.478569861898606&layer=mapnik">
</iframe>
</div>

almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Update your script with this

const myIframe = document.getElementsByTagName("iframe")[0];
if (myIframe) {
  myIframe.style.cssText = 'display: block; visibility: visible;';
}
const parentDiv = myIframe.parentElement.className += ' iframe__wrapper--updated';
console.log(myIframe);
almost 4 years ago · Santiago Trujillo 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!