Brad Bansner
asked on
Exclude elements with a specific class from jQuery selector with eq() filtering
Here is my selector:
When the user clicks a button, this part of it generates a number:
This part of it finds the corresponding H2 element:
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!
var scrollDestination=-parseInt($('h2:eq('+$(this).parent('li').index()+')').parents('div.sectionwrap').position().top);
When the user clicks a button, this part of it generates a number:
$(this.parent('li').index()
This part of it finds the corresponding H2 element:
$('h2:eq(...)')
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, that worked. Thanks! I was trying something similar, I must have just not had the syntax quite right.
alternative the following should also work:
Open in new window
Live sample:
http://jsbin.com/qomita/211/edit?html,js,console,output
HTH
Rainer