1 Example(s) of JQuery Index


Description :

In this example the index() is an inbuilt method in jQuery which is used to return the index of the a specified elements with respect to selector.


JQuery Index Example - 1
<!DOCTYPE html> 
<html> 

<head> 
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> 
	</script> 
	<script> 
		
		$(document).ready(function() { 
			
			$("li").click(function() { 
				document.getElementById("demo").innerHTML = "Clicked Index " + $(this).index(); 
			}); 
		}); 
	</script> 
</head> 

<body> 

	<h1>Click on the elements of the list to display their index 
	number with respect to the other elements in the list.</h1> 
<h1 style="color:crimson"> APPWRK Service
	<ul> 
		<li>Web Service</li> 
		<li>Web development</li> 
		<li>Mobile app development</li> 
	</ul> 
</h1>
	<h1 id="demo" style="color: rgb(32, 24, 145)"></h1> 
</body> 

</html>

Output