2 Replies - 7194 Views - Last Post: 14 June 2011 - 07:39 AM

#1 musya   User is offline

  • D.I.C Lover
  • member icon

Reputation: 11
  • View blog
  • Posts: 1,012
  • Joined: 25-April 07

JQuery change div height

Posted 10 June 2011 - 01:25 PM

I've been trying to change the height of a div but It's not changing it. I've tried a few different approaches, does anyone see what I'm doing wrong?

Method 1:
$(window).resize(function() {
var newheight = "=500";
$("bodyContainer").css("height",newheight);
});


Method 2:
$(window).resize(function() {
var newheight = 500;
$("bodyContainer").height(newheight);
});

This post has been edited by musya: 10 June 2011 - 01:26 PM


Is This A Good Question/Topic? 0
  • +

Replies To: JQuery change div height

#2 anonymouscodder   User is offline

  • member icon

Reputation: 126
  • View blog
  • Posts: 710
  • Joined: 01-January 10

Re: JQuery change div height

Posted 10 June 2011 - 01:38 PM

If bodyContainer is the id of the element, select it with the ID Selector, like $("#bodyContainer").

If it is the class of the element, select it with the Class Selector, like $(".bodyContainer").

I'm pretty sure that method one is wrong, it should be .css("height",500); or .css("height","500");. Method 2 is fine.
Was This Post Helpful? 0
  • +
  • -

#3 sithius92   User is offline

  • D.I.C Head
  • member icon

Reputation: 36
  • View blog
  • Posts: 164
  • Joined: 01-August 08

Re: JQuery change div height

Posted 14 June 2011 - 07:39 AM

There is a height() method in jQuery. You can pass it a parameter to set the height of the selected element. Just remember to use either (#) for selecting elements by id or (.) for selecting elements by class like anonymouscodder suggested. Not including either one of these will try to select the html element. For example, $("tr") will select all tr elements of the document.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1