For example, with a font-size switcher/button, if I use
$('#container p').css('font-size', '24px');
it works as expected, but if I later add paragraph elements to the container (via ajax, etc), they are not styled with the updated font-size. I am aware that this is the intended behavior of the .css()
method. I am simply asking:
What's the proper approach to changing a style for a CSS selector, and making those styles persistent?
Right, well, when you perform that command, it styles all p
elements in #container
. If you want it to be permanent, you could create a <style />
element and add the CSS stylings there.
To elaborate, you could do something like this:
$(document.head).append('<style>#container p{font-size: 24px;}</style>');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With