Kirzilla
Kirzilla

Reputation: 16596

How to remove all tags after certain tag?

I need to remove tags going after #first and only in #container. How can I do it with jQuery?

<div id="container">
  <div id="first"></div>
  <div id="remove_me_1"></div>
  <div id="remove_me_2"></div>
  <div id="remove_me_3"></div>
  <a href="" id="remove_me_too">Remove me too</a>
</div>

Thank you

Upvotes: 5

Views: 902

Answers (3)

karim79
karim79

Reputation: 342635

$("#container :gt(0)").remove();

Upvotes: 1

mamoo
mamoo

Reputation: 8166

You can use nextAll method: http://api.jquery.com/nextAll/

$("#first").nextAll().remove();

Upvotes: 11

Emil Vikstr&#246;m
Emil Vikstr&#246;m

Reputation: 91922

$.("#container #first ~ *").remove();

Upvotes: 1

Related Questions