Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get left, right values with out px in jquery [duplicate]

Tags:

jquery

Possible Duplicate:
Left() function in Javascript or jQuery

I have one div and i give style like below.

#MainDiv
{
    position:relative;    
    left:150px;
    right:150px;

}

I want to give the width of this #MainDiv based on the left and right parameters. For this I give like below.

$("#MainDiv").width($("#MainDiv").width() - $("#MainDiv").css("left") - $("#MainDiv").css("right"));

But $("#MainDiv").css("left") is giving me 150px in the alert. I want only the 150. For that I used offset property, $("#MainDiv").offset().left and $("#MainDiv").offset().right. The left value is coming as 158 and right is coming as undefined. offset is not correct at this situation? How should I remove that px at the end of the value and get the exact value?

like image 408
Mihir Avatar asked Dec 11 '22 19:12

Mihir


1 Answers

do:

var left = parseInt($("#MainDiv").css("left"), 10);
like image 80
Sudhir Bastakoti Avatar answered Jan 19 '23 15:01

Sudhir Bastakoti