jQuery provides 2 very useful functions .prev() and .next() to refer to the immediate previous/next sibling of a given control. This is to be noted that these functions limit to the current reference of a DOM element.
From the jQuery documentation:
- .prev() gets the immediately preceding sibling of each element in the set of matched elements, optionally filtered by a selector
- .next() gets the immediately following sibling of each element in the set of matched elements. If a selector is provided, it retrieves the next sibling only if it matches that selector.
- <div id="div1">
- <input type="text" id="d1t1" />
- <input type="text" id="d1t2" />
- <input type="text" id="d1t3" />
- </div>
- <div id="div2">
- <input type="text" id="d2t1" />
- <input type="text" id="d2t2" />
- <input type="text" id="d2t3" />
- </div>
Considering the same example above, let's see the following jQuery snippet:
- <script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.js"></script>
- <script type="text/javascript">
- $(function () {
- $("#d1t2").focusout(function () {
- alert($(this).prev().val());
- alert($(this).next().val());
- });
- });
- </script>
I hope this gives you a brief insight on how the .prev() and .next() functions work. In case you have any questions, let me know.
Keep learning & sharing!

Gopi ChandPosted May 4, 2015, 2:58 PM
Its good one...
Karthik Muthu KaruppanPosted May 4, 2015, 1:56 PM
good
Santhakumar MunuswamyPosted May 3, 2015, 11:44 PM
Thanks for nice article