tags:

views:

92

answers:

4

Hi

I use a website, which shows information i have no use for, so i tried to hide some of it with Stylish, an addon for Chrome to insert custom CSS.

I will try to explain better.

<div class="splitscreenleft"> <div id="toplevel"

<div class="splitscreenleft"> <div id="coursesection"

I want to hide one of those. Everything above splitscreenleft is the same on both. So the only difference is the div id below.

I must somehow hide one of the two classes based on the name of the div below it i think. Any solutions to this problem?

+2  A: 

You should be able to do this either via CSS or JavaScript.

You probably don't even need to search the children out. You can probably just pick the first or second one that appears on the page and style that. To do via CSS, use the first-of-type selector - http://www.w3.org/TR/css3-selectors/#first-of-type-pseudo

div.splitscreenleft:first-of-type { display: none; }

To do this via JavaScript, you can find the parent object and then hide it: document.getElementById("toplevel").parentNode.style.display = 'none';

You should be able to do it similarly in jQuery:

$(".splitscreenleft:has(#toplevel)").hide();​

Aaron D
[code] <div class="splitscreenleft"> <div id="toplevel" class="section"> [/code] Here is an example of the code, the class "splitscreenleft" is the one there is two of. The only difference is the next div id below.first-of-type selector was new to me, so it was a little hard to understand, but can i use it to remove one "splitscreenleft" who have the div id "toplevel" below?Thanks for fast help :)
A: 

This can be accomplish by CSS, using structural pseudo-classes alone:

.parentClassName .className :nth-child(n) { display: none; }

Where n is the element you want to select. In your case you have two elements with the same class. To hide the first one, just replace n with 1, or 2 to hide the second one. You get the idea.

Espresso
This one does the opposite of what i want, it removed the content of the div below the class. I want to remove 1 of 2 classes who have the same name, only difference between them is the divs inside them.
There are two divs with the same class name in a parent element. You want to remove one of them? Try adding the parent element's id or class. Take a look at the code, I updated it.
Espresso
The class there is two of is the parent, and everything above them is the same, the only way to see the difference is to check the divs inside.One islike this:<div class="splitscreenleft"> <div id="toplevel"And the other like this:<div class="splitscreenleft"> <div id="coursesection"
A: 

If you can't get access to jQuery with JS (haven't tried in chrome), you could always say

$('#topLevel').parent().hide();
Stefan Kendall
A: 

the code below can change the class you defined in style sheet.

document.getElementById("testPara").className = "yourclass";
huangli