Methods to modify element width (width): 1. Use width() to directly set the width value, the syntax is "$(selector).width("width value")"; 2. Use css() to add width New style, the syntax is "$(selector).css("width","width value")".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
jquery changes element width (width)
##1. Use the width() method
The width() method returns or sets the width 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").width("200px"); }); }); </script> </head> <body> <img src="1.jpg" style="max-width:90%"/ alt="How to modify element width (width) in jquery" ><br> <button>修改元素的宽度</button> </body> </html>
2. 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("width","250px"); }); }); </script> </head> <body> <img src="1.jpg" style="max-width:90%"/ alt="How to modify element width (width) in jquery" ><br> <button>修改元素的宽度</button> </body> </html>
jQuery video tutorial、web front-end video】
The above is the detailed content of How to modify element width (width) in jquery. For more information, please follow other related articles on the PHP Chinese website!