Home > Web Front-end > Front-end Q&A > How to change the height of an element in jquery

How to change the height of an element in jquery

藏色散人
Release: 2021-11-11 10:09:33
Original
4760 people have browsed it

Jquery method to change the height of an element: 1. Create a new HTML file; 2. Create a module using the div tag; 3. Use css to set the style of the div through the id; 4. Create a button; 5. Create the addheight() function in the js tag; 6. Use height() to set the div height.

How to change the height of an element in jquery

The operating environment of this article: windows7 system, jquery version 3.2.1, DELL G3 computer

How does jquery change the height of an element?

Use jquery to dynamically change the height of a div:

Create a new html file, named test.html, to explain how to use jquery to dynamically change the height of a div.

How to change the height of an element in jquery

In the test.html file, use the div tag to create a module and set its id to mytest.

How to change the height of an element in jquery

In the css tag, use css to set the style of the div through the id, define the height of the div as 100px, the width as 100px, and the background color as yellow.

How to change the height of an element in jquery

In the test.html file, use the button tag to create a button with the button name "Change the height of the div".

How to change the height of an element in jquery

In the test.html file, bind the onclick click event to the button button. When the button is clicked, execute the addheight() function.

How to change the height of an element in jquery

In the js tag, create the addheight() function. Within the function, obtain the div object through id(mytest), use the height() method to obtain the height of the div, and then Use height() to set the height of the div again, for example, dynamically add 100px to the height of the div.

How to change the height of an element in jquery

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

How to change the height of an element in jquery

Recommended learning: "jquery video tutorial"

The above is the detailed content of How to change the height of an element in 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