Adding CSS styles to injected DOM elements
Posted
by
Nyxynyx
on Stack Overflow
See other posts from Stack Overflow
or by Nyxynyx
Published on 2012-12-04T04:54:21Z
Indexed on
2012/12/04
5:03 UTC
Read the original article
Hit count: 255
I am using javascript to inject a few DOM elements into the page. I am able to inject a single DOM element and apply CSS style to it:
var $e = $('<div id="header"></div>');
$('body').append($e);
$e.css({
background: '#fbf7f7',
});
Problem: If I have nested elements within $e
, how can I apply CSS styles to the parents and its children seperately?
var $e = $('<div id="header"><div class="header-content"><span class="title"></span></div></div>');
© Stack Overflow or respective owner