The JavaScript code to delete a picture is: "$("Picture Element").remove();"; "$("Picture Element")" can obtain the specified picture element object, and the remove() method can move it Excludes the selected element, including the text and child nodes of the specified element.
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
The remove() method removes the selected element, including all text and child nodes.
This method will also remove the data and events of the selected element.
The syntax is:
$(selector).remove()
The example is as follows:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>123</title> <script src="js/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("img").remove(); }); }); </script> </head> <body> <img src="1118.01.png" alt="What is the JavaScript code to delete an image?" > <button>删除图片元素</button> </body> </html>
Output result:
[Related recommendations: javascript video tutorial, web front-end]
The above is the detailed content of What is the JavaScript code to delete an image?. For more information, please follow other related articles on the PHP Chinese website!