How do I retreive the line-height of an element without the "px"?
Using this I get the full line-height value including the px.
$('#example').css('line-height');
How do I retreive the line-height of an element without the "px"?
Using this I get the full line-height value including the px.
$('#example').css('line-height');
Parse it as an integer with parseInt
parseInt($('#example').css('line-height'), 10);
Outputs:
18
As an integer. The other solutions maintain the String type.
EDIT
For values that may contain decimal points, you can use parseFloat()
parseFloat($('#example').css('line-height'));
Outputs:
18.4
Just replace the px
with ''
.
$('#example').css('line-height').replace('px', '');
save it into a variable an then make a replace
var aux = $('#example').css('line-height').replace('px', '');
In coffeescript
getElementProperty = (el, property) ->
val = el.css(property).replace "px" , ""
parseInt val
getElementProperty $("#myElement"), "line-height"
This should to it !