I have the following code which works fine on the jsfiddle environment. However I can't get it to run outside of it. Im relatively new to javascript so not sure. Do I need to declare the javascript as a function and have it run on page load? The CSS and JS files will ideally be external files if that makes any difference once they've been referenced in the head part of my html.
<html>
<head>
<style>
.container {
width: 100%;
height: 150px;
background : #bbb;
}
.inner {
float:left;
height:100%;
margin-left:20px;
}
</style>
<script>
var containerW = $('.container').width();
var innerCount = $('.container .inner').length;
var containerM = parseInt($('.container .inner').css("margin-left"));
$('.inner').css({
width: (containerW / innerCount) - containerM
})
</script>
</head>
<body>
<div class='container'>
<div class='inner' style='background : #FF0000;'></div>
<div class='inner' style='background : #00FF00;'></div>
<div class='inner' style='background : #FF0000;'></div>
<div class='inner' style='background : #00FF00;'></div>
</div>
</body>
</html>
DEMO
(My code is slightly different to the fiddle but the princple is the same I cant get it to work.
Thanks