Home > Article > Web Front-end > How to modify the height of an element in jquery
Jquery method to modify element height (height): 1. Use the css() method, syntax "$(selector).css("height","height value")"; 2. Use height() Method, syntax "$(selector).height("height value")".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
jquery modifies the height of the element
Method 1: Use the css() method
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="js/jquery-1.10.2.min.js"></script> <script> $(document).ready(function() { $("button").click(function() { $("img").css("height","200px"); }); }); </script> </head> <body> <img src="img/1.jpg" style="max-width:90%"/ alt="How to modify the height of an element in jquery" ><br> <button>修改元素的高度</button> </body> </html>
Method 2: Use the height() method
The height() method returns or sets the height of the matching element.
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="js/jquery-1.10.2.min.js"></script> <script> $(document).ready(function() { $("button").click(function() { $("img").height("200px"); }); }); </script> </head> <body> <img src="img/1.jpg" style="max-width:90%"/ alt="How to modify the height of an element in jquery" ><br> <button>修改元素的高度</button> </body> </html>
[Recommended learning: jQuery video tutorial, web front-end video】
The above is the detailed content of How to modify the height of an element in jquery. For more information, please follow other related articles on the PHP Chinese website!