Thursday, February 07, 2013 at 10:47am

Get Height or Width of Div With jQuery

Written by  Caleb Nance

Today I want to show you how to get the current height and/or width of an element with jQuery and also how to constantly check the height and width of an element as the page is being resized!

First I want to show you how easy it is to get the height and width of the element. The following code does just that.

// Get height
var currentHeight = $('.element_class').height();

// Get width of image inside a div
var currentWidth = $('.div_class img').width(); 

Now lets say you need to refresh your CSS positioning when the screen is being resize... this is how you check and update the value of that element everything the screen is resized, with the resize() function in jQuery.

$(window).resize(function() {
  var currentWidth = $('.div_class img').width();
});

That will do it! Hope this helped.

Last modified on Thursday, February 07, 2013 at 11:01am
Caleb Nance

Caleb Nance

Vinyl record collector. PHP/CSS3/HTML5/jQuery Web Developer. XBox Live SN: JoomlaFTW

Website: calebnance.com

Share it..

Latest from Caleb Nance

Related items (by tag)

More in this category:
blog comments powered by Disqus

Find It..

© Copyright 2008 - 2014 | All Rights Reserved | Caleb Nance