Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7049177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:58:53+00:00 2026-05-28T02:58:53+00:00

How do I add CSS to elements that have been dynamically created? Here is

  • 0

How do I add CSS to elements that have been dynamically created?

Here is a simple example of what I would like to do:

$(document).ready(function() { 
    $('#container').html('<p id="hello">hello world</p>');
    // The following line doesn't work. 
    $('#hello').css("background-color", "#FFF");
});

The reason I want to do this, and I can’t think of another way of doing it, is that I want to use background colour on alternate rows of a table that is dynamically generated:

$("#results-table tr:even").css("background-color", "#FFF");

I need to use this line of jQuery specifically for IE8 and below, which don’t support nth-child CSS selectors.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:58:53+00:00Added an answer on May 28, 2026 at 2:58 am

    Actually, your code does work. You might want to check if you don’t have multiple elements by that ID.

    Edit:
    Here’s your code, without duplicate IDs: http://jsfiddle.net/FhTU7/

    Final edit:
    Your HTML background and element background are both white.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple html snippet that I add to the document during runtime.
I have a fixed-width page that I want to add a simple border to
I have some jQuery code that finds elements with the shaded CSS class and
I have been reading tutorials from several different places like http://css-tricks.com/scrollfollow-sidebar/ or http://jqueryfordesigners.com/fixed-floating-elements/ and
When you want to add whitespace between HTML elements (using CSS), to which element
I need to add css height to each page dynamically with jQuery. So far
I'm trying to add .css and .js file in my HTML template files that
I have, for a while now been using a reset.css file to reset everything
I have a page with many elements that have the same class attached to
The markup below is an example of a dynamically generated menu that is styled

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.