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

177
Vistas
jQuery load body from external HTML

I'm using jQuery and trying to load the body from an external HTML file.

It works if I try to load some div:

$('body').load('example.html #content');

But I'm unable to do something like this:

$('body').load('example.html body');

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

From http://api.jquery.com/load

jQuery uses the browser's .innerHTML property to parse the retrieved document and insert it into the current document. During this process, browsers often filter elements from the document such as <html>, <title>, or <head> elements. As a result, the elements retrieved by .load() may not be exactly the same as if the document were retrieved directly by the browser.

Reading the above, it seems possible that your browser be only returning the body innerHTML. This obviously should be the same as requesting body, but maybe it's causing an error because body is not found?

I'd suggest trying a different browser.

over 4 years ago · Santiago Trujillo Denunciar

0

If you want to load the whole body, $('body').load('example.html'); should be enough.

If not, could you explain why ?

Anyway, the solution provided by Steve is the right one.

over 4 years ago · Santiago Trujillo Denunciar

0

When you use load without a selector, it strips the <html>, <head>, and <body> tags, but leaves all of the children of <head> and <body> intact, including title, script, and style tags. However, when you use a selector, it is applied after the body tag is stripped, so it's impossible to match against it.

Instead, wrap all of your body content inside another tag, and select that tag instead:

<html><head><title>Hello!</title</head>
<body>
  <div id="jquery-load-point">
    ... <!-- rest of body content -->
  </div>
</body>
</html>

Now, you can load it like this:

$("#destination").load("http://my.url/to/page #jquery-load-point");
over 4 years ago · Santiago Trujillo 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