删除Div的JavaScript该模糊网站
有一个带有以下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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
getElementsByClassName()
返回集合。只有单个对象具有remove()
方法。您必须应用以下一个:div [0] .remove()
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 haveremove()
method. You have to apply one of the following:div[0].remove()
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 usereplaceWith()
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)