andeersg
andeersg

Reputation: 1615

Change name of a html class

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?

Upvotes: 0

Views: 288

Answers (4)

Aaron D
Aaron D

Reputation: 5886

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();​

Upvotes: 2

huangli
huangli

Reputation: 454

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

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

Upvotes: 0

Stefan Kendall
Stefan Kendall

Reputation: 67892

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

$('#topLevel').parent().hide();

Upvotes: 0

Espresso
Espresso

Reputation: 4752

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.

Upvotes: 0

Related Questions