删除Div的JavaScript该模糊网站

发布于 2025-01-29 03:17:58 字数 480 浏览 3 评论 0原文

有一个带有以下div的网站:

<div class="x" style="user-select: none; filter: blur(4px);">

在此Div下,还有许多其他部门。我想知道是否有可能仅使用JavaScript删除此DIV。因此,只有一个人被删除,而下面的所有div则保留在下面。

我想摆脱这个div,因为这个div模糊了网站文本的一部分。只需更改模糊(4PX)即将工作,网站就会有某种保护,使这一部分重新刷新回到了原件。 我要在JavaScript中寻找可能性的原因是因为我想在浏览器中自动化它。(只是在开发人员模式下手动删除DIV),

到目前为止,我得到了以下内容:

var div = document.getElementsByClassName('page-content');
div.remove();  //(but this does not work)

There is a website with the following div:

<div class="x" style="user-select: none; filter: blur(4px);">

under this div there are a lot of other divs. I would like to know if there is any possibility to delete only this DIV with javascript. So only that one gets deleted and all the divs underneath remain.

I want to get rid of this DIV becouse this div blurs an part of the website text. Just changing the blur(4px) wont work the website has some kind of protection what refreshes this part back to original.
the reason i am searching for an possibility in javascript is because i want to automate this in the browser.(Just deleting DIV manually under developer mode works)

so far i got the following:

var div = document.getElementsByClassName('page-content');
div.remove();  //(but this does not work)

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

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

发布评论

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

评论(1

转瞬即逝 2025-02-05 03:17:58

getElementsByClassName()返回集合。只有单个对象具有remove()方法。您必须应用以下一个:

  1. 使用括号来指定要获取的对象的索引:

div [0] .remove()

  1. 使用iteg> iteg> item()方法也通过索引:

div.Item(0).remove()

两种方式都是等效的。

作为替代方案,您可以调用querySelector()方法:

const dim = document.queryselector('。page-content')

它返回一个对象(根据传递CSS选择器)因此您可以使用:

div.Remove()

编辑:

仅删除封面div,您可以使用replace>替换()方法并传递该div的子节点作为参数:

div.replacewith(... Div.ChildNodes)

如果要保留元素节点,请使用儿童属性:

div.replacewith(... Div.Children)

getElementsByClassName() returns a collection. Only single objects have remove() method. You have to apply one of the following:

  1. Use brackets to specify an index of the object you want to get:

div[0].remove()

  1. Use item() method passing the index as well:

div.item(0).remove()

Both ways are equivalent.

As an alternative, you may call querySelector() method:

const div = document.querySelector('.page-content')

It returns a single object (according to the passed CSS selector) so you can use:

div.remove()

Edit:

To remove only the covering div, you may use replaceWith() method and pass the child nodes of that div as an argument:

div.replaceWith(...div.childNodes)

If you want to keep only element nodes, use children property:

div.replaceWith(...div.children)

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