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 add styles to a appended div done through Javascript in Css file

this is my html file

                      <div id="addingMembers">

                      </div>

                       <div class="selectMember">
                            <div class="selectTitle" (click)="addMember()">
                                <p class="selectMemTitle">Add a member</p>
                                <mat-icon aria-hidden="false" aria-label="add icon">add_circle_outline</mat-icon>
                            </div>
                        </div>

this is my Javascript File:

  addMember(){
    const x = document.getElementById('addingMembers');   
    x.innerHTML+ = 
      `<div id="members">
      Hey I'm added
        </div> 
      `;
}

Here, I want to style my members div using CSS File, but the styles are not applying on it:

#addingMembers #members{
    background-color: red;
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Use ::ng-deep pseudo-class to disables view-encapsulation. Or move your styles to global styles.

::ng-deep #addingMembers #members{
  background-color: red;
}
about 4 years ago · Juan Pablo Isaza Report

0

Add a class to the control you are adding. Check below sample.

function tes() {
            let change = document.getElementById("addingMembers");

            change.innerHTML = '<input type="text" class="randomCls"/>';
        }
 .randomCls{
            background-color:red;
        }
<div id="addingMembers">
        </div>
        <input type="button" id="btn1" onclick="tes()" value="Check" />

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!