Is it possible to apply CSS styles to dynamically created elements?
Let's take a look at a basic example of what I am trying to achieve:
$(document).ready(function() {
$('#container').html('<p id="hello">hello world</p>');
// The code snippet below is not working as expected.
$('#hello').css("background-color", "#FFF");
});
I have this requirement because I want to add background colors to alternating rows in a dynamically generated table:
$("#results-table tr:even").css("background-color", "#FFF");
This jQuery line is specifically needed for dealing with IE8 and older versions, which do not support the use of `nth-child` CSS selectors.