
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Change First and Last Elements of a List using jQuery
To change the first and last elements of a list use the eq() method.
Example
You can try to run the following code to change first and last elements of a list using jQuery:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#list li:eq(2)").after($("#list li:eq(0)")); }); </script> </head> <body> <p>This year's ranking:</p> <ul> <li>India</li> <li>US</li> <li>UK</li> </ul> <p>Last year's ranking:</p> <ul id="list"> <li>India</li> <li>US</li> <li>UK</li> </ul> </body> </html>
Advertisements