Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

255
Vistas
Using innerHTML to get a whole page content

I am still a beginner in Javascript and I wondering if I can use innerHTML to post the whole HTML content from another page. I have used innerHTML to just post an HTML code within the same .js page. For example:

I have main.js that contains this

class MyComponent extends HTMLElement {
  connectedCallback() {
this.innerHTML = `<h1>Hello world</h1>`;
  }
}

customElements.define('my-component', MyComponent);

and in the index.html I use this code to implement the main.js

<!doctype html>
<html lang="en">
<head>
<script type="application/javascript" src="js/main.js"></script> 
</head>
   
<body>
    <my-component></my-component>
</body>
</html>

The question is can I include an HTML page instead <h1>Hello world</h1> like header.html to get the whole HTML code from it? if not, Is there any way to do that? Thanks.

Edit: I mean for example if I have a page named footer.html and in that page, I have an h1 ex. "Hello world" And I need to use the same h1 in another page index.html without rewrite it again. Can I make that h1 as a template to use in any other page using javascript? My idea that I was looking for is:

  • Making main.js
  • get h1 from footer.html in main.js
  • import that script in index.html
  • using h1 in index.html I know that I can do that using "include" in PHP but I am just trying to do it by javascript.
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can do that with AJAX. Set an URL for that file and make a get request with AJAX.

Using JQUERY

$.get("file_path.html", function(fileText){});
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can try:

document.body.innerHTML

to access page content.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda