Home >Web Front-end >JS Tutorial >What is the function in jquery that can change the height of elements?
Functions in jquery that can change the height of elements: 1. height(), which can set the height of matching elements, the syntax is "$(selector).height (height value)"; 2. css(), syntax "$(selector).css("height","height value")".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
Function in jquery that can change the height of elements
##1. Height() function## The #height() method sets the height of the matching element.
Syntax:
$(selector).height(length)
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="js/jquery-1.10.2.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("button").click(function() { $("div").height(100); }); }); </script> <style type="text/css"> div { height: 50px; border: 1px solid red; } </style> </head> <body> <div></div> <br /><br /> <button>改变div元素的高度</button> </body> </html>2. css() function
css( ) method sets the style attributes of the matching element.
Grammar:
$(selector).css(name,value)
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="js/jquery-1.10.2.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("button").click(function() { $("div").css("height","200px"); }); }); </script> <style type="text/css"> div { height: 50px; border: 1px solid red; } </style> </head> <body> <div></div> <br /><br /> <button>改变div元素的高度</button> </body> </html>
Recommended related tutorials:
jQuery video tutorialThe above is the detailed content of What is the function in jquery that can change the height of elements?. For more information, please follow other related articles on the PHP Chinese website!