I need some help I have made a style switcher, but I cannot work out how to replace the stylesheet, at the moment my code empties the <head>
where I need it to just replace the previous stylesheet, this is my code,
Menu and javascript
<ul id="options">
<li><a class="option" href="<?php echo base_url();?>welcome/setBackground/red">Red</a></li>
<li><a class="option" href="<?php echo base_url();?>welcome/setBackground/green">Green</a></li>
<script type="text/javascript">
$('a.option').click(function(ev) {
ev.preventDefault();
var url = $(this).attr("href");
alert(url)
$.ajax({
url : url,
type : "POST",
data : "js=true",
success : function(html) {
$('head').html(html);
}
});
});
</script>
PHP
function setBackground() {
$data['style'] = $this->uri->segment(3);
$_COOKIE[] = setcookie("style", $data['style'], time()+(60*60*24*30), "/");
//die(print_r($_COOKIE));
if($this->input->post('js') == "true") {
//echo $data['style'];
$this->load->view('base/cssSelector', $data);
} else {
redirect(base_url().'welcome');
}
}
HTML that javascript and PHP build
<link rel="stylesheet" href="/media/css/<?php echo $style; ?>.css" media="screen, projection" />