Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to 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
