Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • jQuery Tutorial
  • jQuery Selectors
  • jQuery Events
  • jQuery Effects
  • jQuery Traversing
  • jQuery HTML & CSS
  • jQuery AJAX
  • jQuery Properties
  • jQuery Examples
  • jQuery Interview Questions
  • jQuery Plugins
  • jQuery Cheat Sheet
  • jQuery UI
  • jQuery Mobile
  • jQWidgets
  • Easy UI
  • Web Technology
Open In App
Next Article:
How to reverse array of DOM elements using jQuery ?
Next article icon

How to select all next sibling elements of an element using jQuery ?

Last Updated : 30 May, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will discuss how to select all the next sibling elements of an element using jQuery. To select all the next sibling elements of an element, we will use nextAll() method.

The nextAll() method is used to find the next sibling elements of the selected element. The siblings are those having the same parent element in DOM Tree. This method does not accept any parameter and returns all the next sibling elements of the selected element.

Syntax:

$(selector).nextAll()

Approach: First, we will create heading elements and the main div container and inside the main div container, we will add two div containers. When the user clicks on the button, the nextAll() method is called and it selects all the next siblings of the selected element. After selecting the siblings, we add some CSS properties to them.

Example: In this example, we will use nextAll() method.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport"            content="width=device-width, initial-scale=1.0">     <script src= "https://code.jquery.com/jquery-3.5.1.min.js">     </script>     <title>         How to select all next sibling elements         of an element using jQuery?     </title>     <style>         .main {             width: 450px;             text-align: justify;             font-size: 18px;         }         #GFG {             padding: 5px 15px;             margin-top: 20px;         }         .Geeks {             font-size: 18px;             font-weight: bold;             color: green;         }     </style>     <script>         $(document).ready(function () {             $("#GFG").on('click', function () {                 $("h3").nextAll().addClass("Geeks");             });         });     </script> </head>  <body>     <center>         <h1 style="color: green;">             GeeksforGeeks         </h1>         <h3>             How to select all next sibling elements             of an element using jQuery?         </h3>         <div class="main">             <div class="section1">                 HTML stands for HyperText Markup                 Language. It is used to design                 web pages using a markup language.                 HTML is the combination of                 Hypertext and Markup language.             </div>             <br>             <div class="section2">                 Cascading Style Sheets, fondly                 referred to as CSS, is a simply                 designed language intended to                 simplify the process of making                 web pages.             </div>         </div>         <input type="button"                 id="GFG"                 value="Remove Contents">     </center> </body>  </html> 

Output:


Next Article
How to reverse array of DOM elements using jQuery ?

V

vkash8574
Improve
Article Tags :
  • Web Technologies
  • JQuery
  • jQuery-Methods
  • jQuery-Questions

Similar Reads

  • How to select all sibling elements of an element using jQuery ?
    In this article, we will discuss how to select all sibling elements of an element using jQuery. To select all sibling elements of an element, we will use the siblings() method. The siblings() method is used to find all sibling elements of the selected element. The siblings are those having the same
    2 min read
  • How to Select a Range of Elements using jQuery ?
    Given an HTML document with a range of similar elements and the task is to select a range of those elements with the help of JavaScript. There are two approaches that are discussed below with an example. Approach 1: First, select all elements of class = 'child' by jQuery selector then use slice() me
    2 min read
  • How to get text contents of all matched elements using jQuery ?
    In this article, we will see how to get the text content of all matched class elements using jQuery. To get the text content, we use the text() method, which helps to set or return the text content of the element. Syntax: $('Selector').text();Approach 1: We create a div element that contains multipl
    2 min read
  • How to select all ancestors of an element in jQuery ?
    In this article, we will select all the ancestor elements of an element in jQuery. To select all ancestor elements of an element, the parents() method is used. This method is used to find all the parent elements related to the selected element. This method traverses all the levels up the selected el
    1 min read
  • How to reverse array of DOM elements using jQuery ?
    Given an array of DOM elements, the task is to reverse this array using jQuery. There are two approaches that can be taken to achieve this: Approach 1: Use inbuilt jQuery methods such as get(), reverse(), and each(). Firstly, select all the required DOM elements using the get() method which returns
    2 min read
  • How to select specific ancestors of an element in jQuery ?
    In this article, we will select specific ancestor elements of an element in jQuery. To select the specific ancestor elements of an element, we use the parents() method. This method is used to find the parent elements related to the selected element. This parent () method traverse all the levels up t
    1 min read
  • How to Select All Elements without a Given Class using jQuery?
    In jQuery, selecting elements that do not have a specific class can be useful when you want to manipulate or style all elements except those matching a certain condition. This approach allows for more precise control over the elements in various dynamic situations. Here we have some common approache
    2 min read
  • How to Delete All Table Rows Except First One using jQuery?
    To delete all table rows except the first one using jQuery, you can target the rows and remove them while keeping the first row intact. ApproachFirst, we create a table using <table> tag and add a button containing btn id. When a user clicks on the button, then the jQuery function is called. T
    1 min read
  • How to select direct parent element of an element in jQuery ?
    In this article, we will select the direct parent element of an element using jQuery. To select the direct parent element, the parent() method is used. This method finds the parent element related to the selected element. This parent() method traverses a single level up the selected element and retu
    1 min read
  • How to select multiple elements using jQuery ?
    In this article, we will learn how to select multiple elements using JQuery. JQuery is the fastest and most lightweight JavaScript library that is used to simplify the interactions between an HTML/CSS document, or more precisely the Document Object Model (DOM), and JavaScript. JQuery is widely famou
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences