Use jQuery to find next element by class after button clicked

In the following markup, if the user clicks the element with class="jumptoaas", I want to locate the position of the next element with class="aas". I tried this:

console.log($(this).nextAll('.aas').offset().top);

But I get an error message. There will be multiple elements on my page with these two classes, so I want to make sure no matter which class="jumptoaas" is clicked, it always locates the next one in the markup.

Thank you!

<div id="mvi4" class="subpage">
	<ul class="light">
		<li><a class="jumptoaas" href="javascript:void(0)">AWARDS &amp; SETTLEMENTS</a></li>
	</ul>

	<h1>MOTORCYCLE ACCIDENTS</h1>

	<p>Most motorcycle accidents in Pennsylvania are the result of other motorists failing to see the motorcycle in traffic. And the result is almost always severe injuries, long-term disability or death. The cost of medical treatment, the pain and suffering, the medical complications, the loss of income &mdash; the effects can be devastating. That's why there are laws in place to help victims and their families put the pieces of their lives and future back together as much as possible.</p>

	<p>In Philadelphia and all other areas of PA, call us toll free at 800.471.4691.</p>

	<h1 class="aas">AWARDS &amp; SETTLEMENTS</h1>

	<p class="red">Motorcycle Accident Settled for $1/2-million</p>

	<p>A settlement of $500,000 has been announced on behalf of a motorcyclist who suffered neck, shoulder, arm and hand injuries in a collision with an automobile. The motorcyclist, who was in his late 50s at the time of the accident, was traveling straight when a motor vehicle attempted to turn left directly in front of him.</p>
</div>

Open in new window

Brad BansnerWeb DeveloperAsked:
Who is Participating?
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.

Tom BeckCommented:
You would need to get to the same level as the next class='aas' to use nextAll.

console.log($(this).parent('li').parent('ul').nextAll('.aas').offset().top);
0

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
Brad BansnerWeb DeveloperAuthor Commented:
Perfect, thank you so much!
0
Tom BeckCommented:
No problem, thanks for the points.
0
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.