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

103
Vistas
How to wrap dynamic HTML from database around existing HTML via javascript

I need to be able to inject static XHTML code (that's being pulled from a database) and wrap it around existing HTML tags.

HTML PAGE:

<html>
<head><head>
<body>
    <div>
        <!-- Top half of XHTML wrapper goes here //-->

        <p>Inner Content Here</p>
        <!-- etc. --->
        <p>More Inner Content</p>

        <!-- Bottom half of XHTML wrapper goes here //-->
    </div>
</body>
</html>

XHTML WRAPPER FROM DATABASE:
(this is variable content that comes from another system and is user created)

This data comes down via json string. I needs to be split() on the "{{INNER_CONTENT_PLACEHOLDER}}" placeholder and then wrapped around the content noted above. There can be a LOT more wrapper code than I've shown here in my

<div class="myCustomBackground">
    <h1 class="myCustomHeader">MyCompany, Inc.</h2>
    <div class="container-padding">
        {{INNER_CONTENT_PLACEHOLDER}}
    </div>
</div>

Is there a way to inject HTML without the javascript closing the tags so that they bottom half injection can be the closing tags?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you add an id attribute to the outer wrapper:

<html>
<head><head>
<body>
  <div id="outerdiv">
    <!-- Top half of XHTML wrapper goes here //-->

    <p>Inner Content Here</p>
    <!-- etc. --->
    <p>More Inner Content</p>

    <!-- Bottom half of XHTML wrapper goes here //-->
  </div>
</body>
</html>

and also the inner padding:

<div class="myCustomBackground">
   <h1 class="myCustomHeader">MyCompany, Inc.</h2>
   <div class="container-padding" id="innerdiv">
     {{INNER_CONTENT_PLACEHOLDER}}
   </div>
</div>

then you should be able select the content into a variable and then replace the content with the wrapper from the database, and finally insert the content from the variable into the inner wrapper:

var outer = document.getElementById('outerdiv');
var content = outer.innerHTML;
outer.innerHTML = dbstuff;

var inner = document.getElementById('innerdiv');
inner.innerHTML = 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