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

68
Views
How to set content for template in JavaScript

From the below code not able to get the id for template. Trying to set content for template using id. But not working. How to do in JavaScript.

HTML:

 <template id="management" is="dom-if" if="[[flag]]"> </template>

JavaScript:

var flag = true;
const appDiv = document.getElementById('management');
appDiv.innerHTML = `<h1>Power management</h1>`;

Demo: https://stackblitz.com/edit/anagram-implementation-nimzfz?file=index.html,index.js

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

That is not how templates are to be used. You get the template content and THEN manipulate the content and then insert the (cloned) manipulated content into the page DOM

const appDiv = document.getElementById('management').content;
appDiv.querySelector("h1").textContent = `Power management`;
document.querySelector("body").appendChild(appDiv)
<template id="management">
  <div>
    <h1></h1>
  </div>
</template>

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!