How to assign CSS statements to class names with blank inside?

74 views
Skip to first unread message

Ben Stover

unread,
Oct 2, 2013, 11:41:36 AM10/2/13
to Greasemonkey Users
Assume I have the following HTML code (mind the blank inside!):

<div class="aaa bbb">
...
</div>

How can I assign a new GM CSS statement to this div element?
The following ("as usual") does NOT work:

GM_addStyle("div#aaa bbb { display: none !important; }");

Thank you
Ben









Anthony Lieuallen

unread,
Oct 2, 2013, 2:38:27 PM10/2/13
to greasemon...@googlegroups.com
I respect your enthusiasm.  However, from the style of recent questions you've been posting, it seems like you'd greatly benefit from some basic instruction on javascript, especially the DOM and CSS.  Perhaps start reading at:

http://wiki.greasespot.net/Tutorials

Matt Sargent

unread,
Oct 2, 2013, 5:21:50 PM10/2/13
to greasemon...@googlegroups.com
Use GM_addStyle to create the new class 'ccc', with the CSS attributes
you want.

GM_addStyle(".ccc { visibility: hidden; }");


Assuming myDiv is the element you want to add this new class to...

myDiv.classList.add('ccc');

or if you want to just flip the visibility state, regardless of what it
currently is, use "toggle" instead of "add" on the classList.

jerone

unread,
Oct 3, 2013, 9:19:52 AM10/3/13
to greasemon...@googlegroups.com
Anthony Lieuallen is right. This is basic CSS and following some tutorials will help you a lot: http://www.w3schools.com/html/ & http://www.w3schools.com/css/ and finally http://www.w3schools.com/js/

To answer your question:

GM_addStyle("div.aaa.bbb { display: none !important; }");

Zulkarnain K.

unread,
Oct 11, 2013, 6:03:12 PM10/11/13
to Greasemonkey Users, Ben Stover
I already explained about it
at https://groups.google.com/d/msg/greasemonkey-users/hXl56__DUD4/ETFkDfYViWAJ

> On Fri, Jul 5, 2013 at 11:19 PM, I wrote:
>>
>> For class attribute, use 'period' notation.
>>
>> p.myp
>>
>> See http://www.w3.org/TR/css3-selectors/ for reference.
>>
>>
>
> <element class="foo bar"> means that the element has two classes,
> "foo" and "bar".
>
> Use
> GM_addStyle("div.foo.bar { display: none !important; }");
>
> Alternatively, you can use attribute selector
> GM_addStyle("div[class='foo bar'] { display: none !important; }");
>





--
Zulkarnain K.
https://userscripts.org/users/12
Reply all
Reply to author
Forward
0 new messages