---
title: "jQuery nextUntil() method do to select a tag in a document"  
description: "jQuery nextUntil() method do to select a tag in a document"  
author: "Ethan Karla"  
published: 2021-07-28  
updated: 2023-06-14  
canonical: https://www.mindstick.com/forum/156665/jquery-nextuntil-method-do-to-select-a-tag-in-a-document  
category: "jquery"  
tags: ["jquery"]  
reading_time: 2 minutes  

---

# jQuery nextUntil() method do to select a tag in a document

What does the jQuery nextUntil() [method](https://www.mindstick.com/forum/166/webservice-method) do to [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) a tag in a [document](https://www.mindstick.com/articles/328642/what-to-consider-while-choosing-a-software-documentation-tool)?

## Replies

### Reply by Aryan Kumar

The jQuery nextUntil() method is used to find all next sibling elements between two given arguments. Sibling elements are elements that share the same parent. The nextUntil() method traverses forward along siblings of DOM elements.

The syntax for the nextUntil() method is:

Code snippet

```plaintext
$(selector).nextUntil(stop[, filter]);
```

The selector argument is a selector that represents a set of DOM elements. The stop argument is a selector that represents an element that will stop the search for next sibling elements. The filter argument is an optional selector that can be used to filter the results.

The nextUntil() method returns a new jQuery object that contains all next sibling elements up to but not including the one matched by the nextUntil() argument.

Here is an example of how to use the nextUntil() method to select all p tags that are next to a h1 tag:

Code snippet

```plaintext
$("h1").nextUntil("p");
```

This will select all p tags that are next to an h1 tag in the document.

Here is another example of how to use the nextUntil() method to select all p tags that are next to a h1 tag, but only if the p tag has the class "my-class":

Code snippet

```plaintext
$("h1").nextUntil("p.my-class");
```

This will select all p tags that are next to an h1 tag in the document, and only if the p tag has the class "my-class".

The nextUntil() method is a powerful tool that can be used to select specific elements in a document.


---

Original Source: https://www.mindstick.com/forum/156665/jquery-nextuntil-method-do-to-select-a-tag-in-a-document

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
