I tried to change the background of a div element inside another div element, but nothing happens. When I look at the code with firebug it shows that the color had been changed but in my browser window I can’t see any changes
HTML
<div id="outer" style="top: 0px; left: 0px; width: 100%; height: 100%">
<div id="inner" style="top: 0px; left: 0px; width: 100%; height: 100%"></div>
</div>
jQuery
function back(){
$('#inner').css('background-color', 'yellow');
}
$(document).ready(function(){
back();
});
You need to set the height of the body and html…
Demo at http://jsfiddle.net/gaby/B2A7V/1
Percentage height is in relation to its container.
In your case the inner div is trying to match the height of its container (the outer div), but what is the outer divs height ?
If they are just put inside an empty page the outer div’s container is the body, which also needs to set its height to 100% (along with html to be sure).
So add
html,body {height:100%;}and it should work..