I want to increase my selected elements height by 10px. Is there a better way without selecting the element twice.
E.g
$(this).height($(this).height()+10);
Is there some method in jquery which handles this that I have missed?
Answer: Use the JavaScript height() method You can set the height of a <div> box dynamically using the jQuery height() method.
jQuery height() Method The height() method sets or returns the height of the selected elements. When this method is used to return height, it returns the height of the FIRST matched element. When this method is used to set height, it sets the height of ALL matched elements.
Basically, $(window). height() give you the maximum height inside of the browser window (viewport), and $(document). height() gives you the height of the document inside of the browser.
In jQuery, height method is used to get the height of any element in HTML. The height method sets and returns the height of the HTML elements. Method 1: The height() method returns the first matched element's height, But the height(value) method sets all matched elements height.
Try something like this:
$(this).height("+=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