I have 2 jQuery functions that basicly are written the same except for their 1st lines:
$(document).ready(function() {
var h = $(window).height();
var w = $(window).width();
$('#foo').css({'height' : h});
$('#foo').css({'width' : w});
});
$(window).resize(function() {
var h = $(window).height();
var w = $(window).width();
$('#foo').css({'height' : h});
$('#foo').css({'width' : w});
});
so I was wondering if its possible to merge them into 1 some how?
As always thanks in advance.
You can trigger the
resizeevent manually:or create an extra function and bind it to both events:
Btw.
$(function(){...});is a shortcut for$(document).ready(function(){...});.