Reputation: 1779
I am trying to set the height of a div by getting the height from another div but it doesn't seem to use the height.
$(".question-toggler").click(function() {
$("#main-content-pane").height()
$(".zebra-helper").fadeToggle("slow", "linear").height("#main-content-pane");
});
$(".handler").click(function() {
$(".zebra-helper").hide("slow", "linear");
});
Upvotes: 0
Views: 98
Reputation: 8169
If you want a one-liner, try this:
$(".zebra-helper").fadeToggle("slow", "linear").height($("#main-content-pane").height());
If you want to use again the same height in that block, store it into a variable, then use it when needed:
var h = $("#main-content-pane").height();
$(...).height(h);
Upvotes: 2
Reputation: 68
What they said. The height() function only understands integers, not DOM objects (#main-content-pane), so you need to store it in a variable first.
Upvotes: 2
Reputation: 1877
Try to set a variable for height and use it.
$(".question-toggler").click(function() {
var someheight = $("#main-content-pane").height()
$(".zebra-helper").fadeToggle("slow", "linear").height(someheight);
});
Upvotes: 1
Reputation: 113335
The height()
returns an integer, so what do you want to do with that value?
Store it in a variable:
var h = $("#main-content-pane").height();
$(".zebra-helper").fadeToggle("slow", "linear").height(h);
or inline (I don't like this method):
$(".zebra-helper").fadeToggle("slow", "linear").height($("#main-content-pane").height());
From documentation:
.height()
Get the current computed height for the first element in the set of matched elements or set the height of every matched element. read more
Upvotes: 2
Reputation: 3330
I think this is what you're wanting -
$(".question-toggler").click(function() {
var cHeight = $("#main-content-pane").height();
$(".zebra-helper").fadeToggle("slow", "linear").height(cHeight);
});
Upvotes: 2