Home >Web Front-end >Front-end Q&A >How to remove body background image in jquery
How to remove the body background image: 1. Use css(), the syntax "$("body").css("background","none");"; 2. Use attr(), the syntax "$("body").attr("style","background:none");".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
Jquery method to remove body background image
Method 1: Use css()
The css() method returns or sets one or more style properties of the matched element.
Use the css() method to directly add a new value "none" to the background attribute and set a new style.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="js/jquery-1.10.2.min.js"></script> <style> body{ background: url(img/2.png) no-repeat; } </style> <script type="text/javascript"> $(document).ready(function() { $("button").click(function() { $("body").css("background","none"); }); }); </script> </head> <body> <button>去掉body背景图片</button> </body> </html>
Method 2: Use attr()
Use attr() to set the style attribute and add background:none
style, overwrites the old style.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="js/jquery-1.10.2.min.js"></script> <style> body{ background: url(img/2.png) no-repeat; } </style> <script type="text/javascript"> $(document).ready(function() { $("button").click(function() { $("body").attr("style","background:none"); }); }); </script> </head> <body> <button>去掉body背景图片</button> </body> </html>
【Recommended learning: jQuery video tutorial, web front-end video】
The above is the detailed content of How to remove body background image in jquery. For more information, please follow other related articles on the PHP Chinese website!