I have a web page with a css theme. When I click a button, the theme changes to another file, but as I try to get some of the new theme properties to work on, I see that they are still not updated in the elements.
The css files are pretty simple:
red.css
.square{ background-color:red; }
blue.css
.square{ background-color:blue; }
index.html file:
<link rel="stylesheet" id="theme" href="red.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="mydiv" class="square" style="width:100px; height:100px;"></div>
<button id="mybutton">Change Theme!</button>
<script>
$('#mybutton').on('click', function(){
console.log($('.square').css("background-color"));
$('#theme').attr('href', 'blue.css');
console.log($('.square').css("background-color"));
alert('When this alert runs, square will still be red, even though the css file has already been switched');
});
</script>
This example is accessible here: http://herofocus.com/temp/
Is there a way to force a refresh on the DOM so that when Alert runs, the theme will alredy have changed?