<?php include "main.php" #this file is supposed to be included after an event occurred ?>
<!-- this should be deleted after include, also styles scripts and everything in this old-content id-->
<div id="old-content">
<link rel="stylesheet" href="custom.css">
some content
</div>
我尝试过,我在旧内容 div 中添加了以下内容,但 jquery 仅包含在模板 main.php
$("#old-content").empty();
Problem with this, is that files are not actually removed and when i view page source i can see the old content at the end
最佳答案
您可以使用.remove()方法从 DOM 中取出元素。当您想要删除元素本身及其内部的所有内容时,请使用它。
$("#old-content").remove();
// find elements
var button = $("button")
// handle click and add class
button.on("click", function(){
$("#banner-message").remove();
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="banner-message">
<p>Hello World</p>
<button>Remove</button>
</div>
关于javascript - PHP 中包含模板时删除旧内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49550589/