1

I am using jQuery 1.7.1

I am trying to optimize some jQuery and need a little help. I have some text that appear in divs with the class of Header, like this:

<div class='Header'>Some Text</div>
<div class='Header'>More Text</div>
<div class='Header'>Even More</div>

Normally, I would do this to slide up every div except for the first one. Later, I would do something similar and have to use jQuery to find the divs again, which is what I am trying to avoid.

// CLOSE ALL EXCEPT THE FIRST
$(".Header:not(:first)").slideUp();

So, I know I want to put my divs with the Header class into an object like this:

var $HeaderArray = $(".Header);

Now I want to perform functions on them, but I can't figure out how to access them the same way that I did previously, using the filters, not and first. What I want to do is something like this:

$HeaderArray:not:first.slideUp();

This doesn't work. What is the right way to use filters to get at the right divs?

2 Answers 2

3

.not is a function, you need to call it, like so:

$HeaderArray.not(':first').slideUp();
Sign up to request clarification or add additional context in comments.

Comments

3

Can you try using .not() function,

$HeaderArray.not(':first').slideUp();

Comments

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.