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

230
Views
Why are the style classes removed from my element when it's appended?

Can you explain me how it works? Im trying to append div with content added by innerHTML and it's works, but with no styling classes.

const el = document.createElement("div");

el.classList.add("col-sm-4", "col-md-3", "py-3");

el.innerHTML = `<div class="card border-primary">
                    <div class="card-body">
                    <img src="https://via.placeholder.com/80" class="img-regular">
                    </div>
                </div>`
                
                
document.getElementById('gallery').appendChild(el);

// }); // commented out by community
<div id="gallery"></div>

so... no bootstrap styling and mansory library also not working.

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

0

You've got 2 opening <div>'s and 3 closing </div>s. Try removing the extra closing tag.

const el = document.createElement("div");
el.classList.add("col-sm-4", "col-md-3", "py-3");
el.innerHTML = `<div class="card border-primary">
  <div class="card-body">
    <img src="${photo.urls.small}" class="img-regular">
  </div>
</div>`
gallery.appendChild(el);
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!