Home > Web Front-end > JS Tutorial > How to get the height of div with jquery

How to get the height of div with jquery

coldplay.xixi
Release: 2020-11-26 15:31:17
Original
4776 people have browsed it

The jquery method to get the div height: first use the div tag to create a line of text, and use css to set its height; then use the [$] symbol to get the div object, and use the [css()] method to get the height attribute value. That is, the height value of the div.

How to get the height of div with jquery

  • This method is suitable for all brands of computers

jquery to get the div height Method:

1. Create a new html file, named test.html, to explain how jQuery can easily obtain the height of a div.

How to get the height of div with jquery

2. In the test.html file, introduce the jquery.min.js library file and successfully load the file before you can use the methods in jquery .

How to get the height of div with jquery

3. In the test.html file, use the div tag to create a line of text, and use css to set the width of the div to 250px, the height to 250px, and the background color to red.

How to get the height of div with jquery

4. In the test.html file, set the id attribute of the div to mydiv, which is mainly used to obtain the div object through the id below.

How to get the height of div with jquery

5. In the test.html file, use the button tag to create a button, bind the onclick click event to the button button, and when the button is clicked, execute geth() function.

How to get the height of div with jquery

6. In the js tag, create the geth() function. Within the function, use the $ symbol to obtain the div object through id (mydiv). Use the css() method to obtain the height attribute value, that is, the height value of the div, and use the alert() method to output the obtained value.

How to get the height of div with jquery

7. Open the test.html file in the browser and click the button to see the effect.

How to get the height of div with jquery

Related free learning recommendations: javascript (video)

The above is the detailed content of How to get the height of div with jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template