• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1949
  • Last Modified:

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:


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>


	<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>

Open in new window

Brad Bansner
Brad Bansner
  • 2
1 Solution
Tom BeckCommented:
You would need to get to the same level as the next class='aas' to use nextAll.

Brad BansnerWeb DeveloperAuthor Commented:
Perfect, thank you so much!
Tom BeckCommented:
No problem, thanks for the points.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now