Exclude elements with a specific class from jQuery selector with eq() filtering

Here is my selector:

var scrollDestination=-parseInt($('h2:eq('+$(this).parent('li').index()+')').parents('div.sectionwrap').position().top);

Open in new window


When the user clicks a button, this part of it generates a number:

$(this.parent('li').index()

Open in new window


This part of it finds the corresponding H2 element:

$('h2:eq(...)')

Open in new window


All I would like to do is also limit the selector so that elements with class="xyz" are ignored. So for example, get the 3rd instance of an H2 element that doesn't have class="xyz".

I tried adding :not() statements to my selector, but that doesn't seem to combine well with :eq() in the same selector, unless I'm not doing something right.

I would appreciate any advice with this.
Thanks!
Brad BansnerWeb DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

skijCommented:
Try this:
var scrollDestination=-parseInt($('h2:not(.xyz):eq('+$(this).parent('li').index()+')').parents('div.sectionwrap').position().top);

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rainer JeschorCommented:
Hi,
alternative the following should also work:
var curIndex = $(this).parent('li').index();
var scrollDestination=-parseInt($('h2:not(.xyz)').slice(curIndex,curIndex+1).parents('div.sectionwrap').position().top);

Open in new window


Live sample:
http://jsbin.com/qomita/211/edit?html,js,console,output

HTH
Rainer
Brad BansnerWeb DeveloperAuthor Commented:
Yes, that worked. Thanks! I was trying something similar, I must have just not had the syntax quite right.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.