I'm writing a fluid layout for my website and I use jQuery to set the DIVs height and width. In the SetHeight function I give the wanted height as the function's first parameter than I subtract the margins and apply the new height.
function SetHeight(height){
var outer = $(this).outerHeight(true);
var current = $(this).height();
var margin = o-c;
height = height-margin;
$(this).css("height",height);
};
Here's the code which triggers the error message:
var h = $(window).height();
$("#Slider").SetHeight(h-260).removeClass("mobile");
I'm using $(document).ready and $(window).resize with a timer to check if I need to resize any DIV.
What I've missed?
You've defined a function, but you're using it like a method on the jQuery object.
if you do this:
you need to use it like this:
If you want to use it like you are, you need to do something like this:
So you might want this:
Then you can use your code:
Which you can use as you did in your example.
Notice that
this
is already a jQuery object, so you don't need to wrap it like:$(this)
. And you should returnthis
at the end to support chaining - like calling.removeClass("mobile")
at the end.See also: http://api.jquery.com/jQuery.fn.extend/