Jquery and CSS switching - is this possible?
Posted
by Joe
on Stack Overflow
See other posts from Stack Overflow
or by Joe
Published on 2010-03-28T10:51:57Z
Indexed on
2010/03/28
10:53 UTC
Read the original article
Hit count: 186
I build a css file using PHP which allows me to easily customize the color of many elements. Is it possible for me to "rebuild" the stylesheet and apply it to the page in the DOM using Jquery?
eg.
<?php
if (isset($_POST['mycolor'])){
$myColor = $_POST['mycolor'];
} else {
$myColor = "blue";
}
?>
<style type='text/css'>
.style1{
color:<?php $myColor;?>;
}
</style>
Now on my page I have a link you can click called "change color to red" and when you click "red" it does a $.post to my php script, which rebuilds the css including .style1 - and allows the page to change the stylesheet.
I haven't tested this but would it even work? If I echo'ed out the new stylesheet after the post into the dom... would it even apply to the page?
© Stack Overflow or respective owner