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
cómo aplicar body.addClass ("className") a iframe desde el documento principal

Tengo una página de WP con iframes incrustados. Hay un widget que cambia el estilo de la página, y necesito que también cambie el estilo de todos los iframes incrustados. El estilo cambia al hacer clic en el botón que tiene el siguiente controlador de eventos:

 NightVersionButton.click(function (event) { // this is a part that changes the page style (and it works) event.preventDefault(); Cookies.set('contrast', 'night', { expires: 7, path: window.cookiePath }); body.removeClass('highcontrast highcontrast2 highcontrast3'); body.addClass('night'); // this is a part that should change the style of all iframes, but it does not work due to the error "Uncaught TypeError: single_iframe.contentDocument.body.addClass is not a function" var all_iframes = document.getElementsByTagName('iframe'); for (let single_iframe of all_iframes) { var iframe_doc = single_iframe.contentWindow ? single_iframe.contentWindow.document : single_iframe.contentDocument; iframe_doc.body.addClass('night'); //$(single_iframe).contents().find('body').addClass('night'); // this jQuery alternative does not work neither } });

Sin embargo, la parte del código JS responsable de cambiar los estilos en todos los iframes no funciona, con el error de consola "Error de tipo no detectado: single_iframe.contentDocument.body.addClass no es una función".

¿Podría sugerir la solución correcta sobre cómo cambiar el JS que también aplicará addClass a todos los iframes?

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!