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

99
Views
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 answers
Answer question

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 Report
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!