ndesign11
ndesign11

Reputation: 1779

jquery .height() not pulling the height

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

Answers (5)

Lorenzo Marcon
Lorenzo Marcon

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

Zak Greene
Zak Greene

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

codebear22
codebear22

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

Ionică Bizău
Ionică Bizău

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

Ross
Ross

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

Related Questions