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?
do:
var left = parseInt($("#MainDiv").css("left"), 10);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With