如何使用JQuery删除动态内容?

发布于 2024-08-30 22:06:23 字数 423 浏览 2 评论 0原文

我有一个由 CMS 生成的 html 页面。我无法修改页面,但可以添加 JavaScript。

每次加载页面时,JavaScript 函数(我无法修改)都会动态地将一个段落插入到页面上。

每当加载该段落时,如何使用 JQuery .remove() 该段落?

例如,当页面首次加载时,它看起来像这样(空白):

<div></div>

然后,几秒钟后,一个 JavaScript 函数(我无法控制)向页面添加一个段落。然后页面看起来像这样:

<div><p id="foo">bar</p></div>

每次动态加载到页面时,如何使用 JQuery 删除 id=foo 的段落?

I have an html page that is generated by a CMS. I cannot modify the page, but can add JavaScript.

Each time the page loads, a JavaScript function (that I cannot modify) dynamically inserts a paragraph onto the page.

How can I use JQuery to .remove() that paragraph whenever it is loaded?

For example, when the page first loads, it look like this (blank):

<div></div>

Then, a few seconds later, a JavaScript function (that I have no control over) adds a paragraph to the page. The page then looks like this:

<div><p id="foo">bar</p></div>

How can I use JQuery to remove the paragraph with id=foo each time it is dynamically loaded onto the page?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慕烟庭风 2024-09-06 22:06:23

您可以使用 liveQuery 插件 来实现此目的:

$("#foo").livequery(function() {
  $(this).remove();
});

You can use the liveQuery plugin for this:

$("#foo").livequery(function() {
  $(this).remove();
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文