I do not want to have to manually do $(“#element”).css(‘attr’,’val’); since I have a lot of elements. The following illustrates what I am trying to do but is not properly working. It is a PHP file but the PHP is irrelevant:
<?
$css1 = "
#ele1 { border: 1 px solid blue; }
#ele2 { border: 1 px solid blue; }
";
$css2 = "
#ele1 { border: 1 px solid black; }
#ele2 { border: 1 px solid black; }
";
?>
<html>
<head>
<style id="appliedCss"></style>
</head>
<body>
....... PAGE HERE .....
<script>
$("#btn1").click(function (e) {
$("#appliedCss").html(<?=$css1?>);
});
$("#btn2").click(function (e) {
$("#appliedCss").html(<?=$css2?>);
});
</body>
</html>
try this
or
or (but be careful with this way, it append the whole styles to the styles-attribute in HTML)