Gihan Lasita
Gihan Lasita

Reputation: 3055

how to get the width of a div using jquery?

There is two columns set likes this

.left_inside_tab{ float: left; padding-left: 25px; width: 45%; }
.right_inside_tab{ float: right; width: 45%;}

and i tried to get width like this

console.log ($('.left_inside_tab').width());
console.log ($('div.left_inside_tab').width());

both gives

45 as result. problem is 45 is not in pixels its percentage

what im doing wrong?

Regards

Upvotes: 0

Views: 8572

Answers (3)

TheBrain
TheBrain

Reputation: 5608

add a display:block; to the classes then use the .outerWidth()

Upvotes: 3

user495093
user495093

Reputation:

Instead of .width() use .outerWidth()

Heres the jQuery Link

Upvotes: 6

bjornd
bjornd

Reputation: 22933

The problem is somewhere outside the code you showed. Here is your code http://jsfiddle.net/g9B4b/, it works fine.

Upvotes: 5

Related Questions