Reputation: 1018
I'm using JQuery to try and get the value of the top
from css.
However, where I have read a lot of things saying $('modal').css('top')
will return a string "40" it is in fact retruning "40px".
Is there any way I can get this into an integer format. The component is not yet rendered on the page, I am trying to find the default position so I can set it using JS. This means that position().Top = 0 etc.
Upvotes: 0
Views: 81
Reputation: 490233
You can use $.fn.position()
to do that...
$('modal').position().top
If that doesn't work in your situation, you could use parseInt()
or parseFloat()
, because some browsers will give you fractional portions of pixels in some situations.
Upvotes: 1
Reputation: 35314
One solution involves regex replacement and cast to Number:
var topInt = Number($('modal').css('top').replace(/px$/,''));
http://jsfiddle.net/6n8xu0gf/1/
Upvotes: 0
Reputation: 11693
Use
parseInt($('.modal').css('top'), 10);
Working Fiddle
So it will not consider px or anything
I hope model is class or id , not Blank
Upvotes: 1