How to use height () in jquery
Editor to share with you how to use height () in jquery, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
In jquery, the height () method is used to set or return the height of the selected element, returning the height of the first matching element with the syntax "$(selector) .height ()"; but you can set the height of all matching elements with the syntax "$(selector) .height (value)".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
The height () method sets or returns the height of the selected element.
When this method is used to return the height, it returns the height of the first matching element. Syntax format:
(selector) .height ()
When this method is used to set the height, the height of all matching elements is set. Simple syntax format:
$(selector) .height (value)
You can also set the height by calling the callback function
$(selector) .height (function (index,currentheight))
Index-returns the index position of the elements in the collection.
Currentheight-returns the current height of the selected element.
Example:
1. Get the height
$(document) .ready (function () {$("button") .click (function () {alert ("height of div:" + $("div"). Height ());})
Displays the height of the div
2. Set the height
$(document) .ready (function () {$("# btn1") .click (function () {$("div") .ready;}) $("# btn2") .click (function () {$("div") .height ("10em");}) $("# btn3") .click (function () {$("div") .height ("200pt");}) Set div height to 500px, set div height to 10em, set div height to 200pt
Note: for em, pt, etc use ""
The above is all the contents of the article "how to use height () in jquery". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!