简体   繁体   English

JavaScript小书签删除导航栏?

[英]Javascript bookmarklet to remove navbar?

I am trying to create a javascript bookmark that will remove a side navbar from a website that I use, but cannot seem to be able to remove it. 我正在尝试创建一个JavaScript书签,该书签将从我使用的网站上删除一个侧面导航栏,但似乎无法将其删除。

The navbar element id I would like to hide is is: 我要隐藏的导航栏元素ID是:

ul.nav.navbar-nav.side-nav.col-md-2

I have tried a few ways from researching online, but with no luck. 我尝试了几种在线研究的方法,但是没有运气。 How can I accomplish this? 我该怎么做?

Here is my attempt: 这是我的尝试:

javascript:(function(){('ul.nav.navbar-nav.side-nav.col-md-2').hide()})();

This is an internal portal website that I use. 这是我使用的内部门户网站。

I am trying to modify/remove the menu once the site is loaded via the browser in the form of a javascript bookmarklet, and am not editing the site's code myself. 一旦通过浏览器以javascript小书签的形式加载了网站,我就试图修改/删除菜单,而不是自己编辑网站的代码。

Without an example of the problem or website it won't be very clear/easy for anyone to help. 没有问题或网站的示例,任何人都很难/很难做到。

But one obvious issue I see is that you are not actually referring to an element directly, you just placed a CSS selector in brackets: 但是我看到的一个明显问题是,您实际上并没有直接引用元素,只是将CSS选择器放在了方括号中:

('ul.nav.navbar-nav.side-nav.col-md-2')

You probably want to use jQuery to get the element: 您可能想使用jQuery来获取元素:

$('ul.nav.navbar-nav.side-nav.col-md-2')

Or if jQuery is not available: 或者,如果jQuery不可用:

document.querySelector('ul.nav.navbar-nav.side-nav.col-md-2').style.display = 'none';

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

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