Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get browser window size using jQuery (useful for responsive web design)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Get browser window size using jQuery (useful for responsive testing)</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(window).bind({
load:function(){
var windowSize = $(window).width();
$('p.window-width').text('Window width = ' + windowSize + 'px');
},
resize:function(){
var windowSize = $(window).width();
$('p.window-width').text('Window width = ' + windowSize + 'px');
},
});
</script>
</head>
<body>
<h1>Resize your browser window to get width:</h1>
<p class="window-width"></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.