Home >Web Front-end >Front-end Q&A >What is the JavaScript code to delete an image?

What is the JavaScript code to delete an image?

WBOY
WBOYOriginal
2022-04-13 17:30:193630browse

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.

What is the JavaScript code to delete an image?

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

What is the JavaScript code to delete an image?

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:

What is the JavaScript code to delete an image?

[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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn