Home >Web Front-end >Front-end Q&A >How to clear element max-width (maximum width) in jquery
Method to clear max-width: 1. Use css(), syntax "$("specified element").css("max-width","none")"; 2. Use attr() , the syntax is "$("specified element").attr("style","max-width:none;")".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
The max-width style of the element
The max-width attribute sets the maximum width of the element.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <textarea>文本框默认宽度</textarea><br> <textarea style="max-width: 400px;">文本框最大宽度400px</textarea> </body> </html>
How to clear element max-width (maximum width) in jquery
Method 1 : Use css() to set the value of max-width to none
<!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() { $("textarea").css("max-width","none"); }); }); </script> <style type="text/css"> textarea{ max-width: 300px; } </style> </head> <body> <textarea>文本框最大宽度300px</textarea><br><br> <button>清除max-width</button> </body> </html>
2. Use attr() to set the value of max-width to none
<!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() { $("textarea").attr("style","max-width:none"); }); }); </script> <style type="text/css"> textarea{ max-width: 300px; } </style> </head> <body> <textarea>文本框最大宽度300px</textarea><br><br> <button>清除max-width</button> </body> </html>
【Recommended learning: jQuery video tutorial, web front-end video】
The above is the detailed content of How to clear element max-width (maximum width) in jquery. For more information, please follow other related articles on the PHP Chinese website!