Home  >  jQuery

Example of .each() in jQuery

May 03, 2013
.each() in jQuery iterates over the calling element throughout the body of Document. .each() executes a function for each matching element. Syntax is
.each( function(index, Element) ) 
Find the example.
<!DOCTYPE html>
<html>
<head>
<style>
p { color:green; cursor:pointer;}
</style>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<p>Click here</p>
<p>to test</p>
<p>each.</p>
<script>
$("p").click(function () {
$( "p" ).each(function (i) {
	if ( this.style.color != "blue" ) {
	   this.style.color = "blue";
	} else {
	   this.style.color = "";
	}
});
});
</script>
</body>
</html> 
Output
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us