Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the effects of jQuery's $(element).css() persistent?

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?

like image 437
anonymous coward Avatar asked Sep 14 '25 07:09

anonymous coward


1 Answers

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>');
like image 73
Alexsander Akers Avatar answered Sep 17 '25 01:09

Alexsander Akers