I have a div with paragraphs inside:
...
...
I want dynamically to apply
With CSS you can define a child selector.
Building on that, you can dynamically add/remove a style class to your div
and the style will apply to the children you specify in that selector.
Let's assume you want to apply this to a specific div
, not any/every one. So give the target div
an identifier:
...
...
Adding a dynamic style with simple javascript:
document.getElementById('foo').style.className='dynamic_style'
The CSS (using combined id and class on a child selector):
div#foo.dynamic_style > p { /* your style definition*/ }