0

I want to hide all div's except the first of a certain id. I tried to write my own jquery but it seems to not be working.

    $("div.hero-featureSwap:not(:first)").css({display:none});

would this hide all the div tags that have an ID of "hero-featureSwap" except the first one? That is my end result

1 Answer 1

3

the value in the CSS object must be a string:

.css({display: "none"});

or:

.css("display", "none");

Or you could just use jQuery's hide() method:

$("div.hero-featureSwap:not(:first)").hide();
Sign up to request clarification or add additional context in comments.

5 Comments

would this work if the hero-featureSwap is an ID and not a class tag?
If it's an ID then there can only be one of them, so :not(:first) makes no sense. It's the only one, so it's always first.
I was trying to had the divs in a carousel because they were overlapping eachother. By doing this, I hide all except the first one. Is there a CSS property that will hide the 2nd+ divs?
display: none is the correct property. Is your question about the property or the selector?
But it sounds like your confusion is about the proper way to construct the HTML, and the difference between classes and IDs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.