Home>Article>Web Front-end> How to change div height using jquery

How to change div height using jquery

青灯夜游
青灯夜游 Original
2022-05-17 19:01:45 4175browse

3 methods: 1. Use "$("div").height(height)" to set a new height value; 2. Use "$("div").css("height" ,"height value")", add a new height style; 3. Use "$("div").attr("style","height:value")".

How to change div height using jquery

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, Dell G3 computer.

There are many ways to modify the height of elements in jquery:

  • height()

  • css()

  • attr()

1. Use height() to modify the div height

height() method can set the height of matching elements. Syntax:

$("div").height(高度值)

Example:

       
一个div元素,高度60px

How to change div height using jquery

2. Use css() to modify the div height

Use css () Add height style to td element, syntax:

$("div").css("height","高度值");

Example: Modify

$(document).ready(function() { $("button").click(function() { $("div").css("height","40px"); }); });

How to change div height using jquery

3 based on the example of method 1. 3. Use attr() modifies the div height

Use attr() to control the style attribute value and add the height style to the td element. Grammar:

$("div").attr("style","height:高度值")

Example: Modify

$(document).ready(function() { $("button").click(function() { $("div").attr("style","height:100px") }); });

How to change div height using jquery

based on the example of method 1 [Recommended learning:jQuery video tutorial,webfront-end video

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

Statement:
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