jQuery: Iterate over three paragraphs and sets their color property red
jQuery Fundamental - II : Exercise-80
Iterate over three paragraphs and sets their color property red.
Sample solution :
HTML Code :
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-git.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Iterate over three paragraphs and sets their color property red.</title>
</head>
<body>
<p>Click here</p>
<p>to iterate through</p>
<p>these paragraphs.</p>
</body>
</html>
JavaScript Code :
$( document.body ).click(function() {
$( "p" ).each(function( i ) {
if ( this.style.color !== "red" ) {
this.style.color = "red";
} else {
this.style.color = "";
}
});
});
See the Pen jquery-fundamental-exercise-80 by w3resource (@w3resource) on CodePen.
Contribute your code and comments through Disqus.
Previous: Find all elements that are disabled.
Next: Finds every paragraph element.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/jquery-exercises/2/jquery-fundamental-exercise-80.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics