Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
40
rated 0 times [  47] [ 7]  / answers: 1 / hits: 37898  / 13 Years ago, mon, january 2, 2012, 12:00:00

For example I want to add 20px to <div id='example'></div>, which is currently 20px.



I could get the existing height and add 20px and input it as the new height, but I wish to learn if there is a better way that might work like a += operator.


More From » jquery

 Answers
-9

You can pass a function into height() that has the element's current height as an argument and the return of the function will be the new height:



$('#example').height(function (index, height) {
return (height + 20);
});


Here is a demo: http://jsfiddle.net/grajh/



Docs: http://api.jquery.com/height/


[#88278] Friday, December 30, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dustin

Total Points: 599
Total Questions: 105
Total Answers: 106

Location: Belarus
Member since Tue, Mar 14, 2023
1 Year ago
dustin questions
;