2

How can I get element width or height value which would be translated as a pixel number? All I got by using .css('width') are the expressions, not even a percentage number, like calc(-25px + 50%).

Edit

my code here. (Chrome)

var bars_width = element.css('width');
$('.histgram-content').css('width', bars_width);
bars_width = parseInt(bars_width.replace('px', '')) * 0.85;
$('.histgram-bar').css('width', (bars_width/data.length).toFixed(0).toString() + 'px');
/*** average Y ***/
var graph_height = $('.histgram-graph').css('height');
graph_height = parseInt(graph_height.replace('px', ''));

var average_height = $('.average-line').css('top');
average_height = graph_height - parseInt(average_height.replace('px', ''));

The average_height returns the expression I said. The last line got the result of 'NaN'.

3 Answers 3

2

You can use any of jQuery's dimension related methods:

Working example

Sign up to request clarification or add additional context in comments.

2 Comments

I don't know why this is not working for me, and how about other css values like 'top'? I tried .css('top'), it directly returned the expression.
Which browser are you using? Seeing your actual code would help a lot.
1

Use window.getComputedStyle(),example: window.getComputedStyle($('div'))['width']

Comments

0

You can height

$('#element-id').height();

You can width

$('#element-id').width();

1 Comment

returns percentage value. I need pixel values

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.