1

Estoy buscando una etiqueta de otra página que también pertenece al mismo dominio, pero no logro encontrarla ¿Qué estoy haciendo mal?

var s = document.getElementById("search");

var x = s.document.querySelector(".red-tag");

x.style.color = "green";
<iframe id="search" src="www.pagina.com"></iframe>


<!-- EN LA OTRA PÁGINA SE ENCUENTRA -->

<div class="red-tag">
<span>Texto</span>
</div>

1
  • Prueba quitar en la segunda línea de código la s en "s.document.querySelector(".red-tag")"
    – WilsonPT
    el 25 mar. 2021 a las 7:31

1 respuesta 1

2

La variable s hace referencia solo a la etiqueta <iframe>, no a su contenido. Necesitas usar la propiedad .contentWindow:

let s = document.getElementById("search").contentWindow;
let x = s.document.querySelector(".red-tag");
x.style.color = "green";

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.