Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
177
rated 0 times [  178] [ 1]  / answers: 1 / hits: 34513  / 13 Years ago, fri, february 17, 2012, 12:00:00

Is there a way in javascript/jQuery to take two variables with values 60px and 40px and add them together to get 100px?



Or in a more general sense, I'm trying to calculate positions of objects relative to other objects and it would be really convenient if I could do something like this:



$('#object2').css('left', $('#object1').css('left')+'60px');


Of course, that just gives in invalid 40px60px.


More From » jquery

 Answers
9

remove px from strings, add values, then add px back



  (parseInt(40px.replace(/px/,))+60)+px

[#87399] Thursday, February 16, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zaynerogerb

Total Points: 454
Total Questions: 109
Total Answers: 97

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
zaynerogerb questions
;