简体   繁体   English

使用JS更改没有ID或类的内联CSS

[英]Changing Inline CSS with no id or class with JS

well I am trying to remove a add from this site anisp.gq put by the hosting provider ... its a practice site just for fun ... 好吧,我试图从托管提供者将此站点anisp.gq中 删除一个添加项 ...它只是一个娱乐性的练习站点...

The server on which the site is hosted puts this add on it after all the code and I have no access to this last bit of code on the admin-panel side : 托管该网站的服务器将所有代码添加到该服务器上,而我无法访问管理面板端的最后一部分代码

<!-- Actual Website Code Above^^^ --> 
<!-- Last bit of add code that I want to remove ↓↓ -->

<div style="text-align:right;position:fixed;bottom:3px;right:3px;width:100%;z-index:999999;cursor:pointer;line-height:0;display:block;">

    <a target="_blank" href="https://www.freewebhostingarea.com" title="Free Web Hosting with PHP5 or PHP7">

    <img alt="Free Web Hosting" src="https://www.freewebhostingarea.com/images/poweredby.png" style="border-width: 0px;" width="180" height="45">

    </a>
    </div>

Hence, I have no access to this last bit of code I decided to use JavaScript to get the inline display tag to change but due to there being no id or class present I am struggling ... 因此,我无法访问这最后的代码,我决定使用JavaScript来更改内联显示标签,但是由于没有id或class,我正在努力工作...

I have been trying to get the style tags display attribute to change to none in this div section ... 我一直试图在此div部分中将样式标签的显示属性更改为无...

But as you can see there is no id and class tag there so 但正如您所见,那里没有id和class标记,因此

document.getElementById("myDIV").style.display = "none"; 

is out of question in my view ... 我认为毫无疑问...

I have been trying you can say stupid stuff like this : 我一直在尝试你可以说像这样的愚蠢的东西:

var node = document.querySelector('[style="text-align:right;position:fixed;bottom:3px;right:3px;width:100%;z-index:999999;cursor:pointer;line-height:0;display:block;"]').display="none";

/*and the below one */ / *和下面的一个* /

 var node = document.querySelector('[style="text-align:right;position:fixed;bottom:3px;right:3px;width:100%;z-index:999999;cursor:pointer;line-height:0;display:block;"]');

document.getElementById("node").style.display ="none";

and some other stuff but nothing works and my lack of knowledge with DOM and JS is not helping either .... so I have no idea what I am doing is right wrong or what ... Please tell me whats the right approach ... 以及其他一些东西,但是没有任何效果,而且我对DOM和JS的缺乏知识也无济于事..所以我不知道我在做什么是对错还是什么...请告诉我什么是正确的方法.. 。

Thanks for Your Time 谢谢你的时间

You could target the child <a> tag and then jump up to the parent. 您可以定位子<a>标记,然后跳转到父标记。

var node = document.querySelector(
  'a[href="https://www.freewebhostingarea.com"]'
).parentNode;

node.style.display = 'none';

Both of your attempts almost works, there's just a small issue in both. 您的两种尝试都几乎可以奏效,两者都只是一个小问题。
For the first one, you are missing style before display. 对于第一个,您在显示之前缺少style

 var node = document.querySelector('[style="text-align:right;position:fixed;bottom:3px;right:3px;width:100%;z-index:999999;cursor:pointer;line-height:0;display:block;"]').style.display = "none"; 
 <div style="text-align:right;position:fixed;bottom:3px;right:3px;width:100%;z-index:999999;cursor:pointer;line-height:0;display:block;"> <a target="_blank" href="https://www.freewebhostingarea.com" title="Free Web Hosting with PHP5 or PHP7"> <img alt="Free Web Hosting" src="https://www.freewebhostingarea.com/images/poweredby.png" style="border-width: 0px;" width="180" height="45"> </a> </div> 

In the latter attempt you are not using the value that you assign to your node variable. 在后一种尝试中,您没有使用分配给node变量的值。 Should be like this: 应该是这样的:

  var node = document.querySelector('[style="text-align:right;position:fixed;bottom:3px;right:3px;width:100%;z-index:999999;cursor:pointer;line-height:0;display:block;"]'); node.style.display = "none"; 
 <div style="text-align:right;position:fixed;bottom:3px;right:3px;width:100%;z-index:999999;cursor:pointer;line-height:0;display:block;"> <a target="_blank" href="https://www.freewebhostingarea.com" title="Free Web Hosting with PHP5 or PHP7"> <img alt="Free Web Hosting" src="https://www.freewebhostingarea.com/images/poweredby.png" style="border-width: 0px;" width="180" height="45"> </a> </div> 

If you want a non-javascript solution, this CSS will do. 如果您需要非JavaScript解决方案,则可以使用此CSS。

div[style="text-align:right;position:fixed;bottom:3px;right:3px;width:100%;z-index:999999;cursor:pointer;line-height:0;display:block;"] {
  display: none !important;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM