Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

jQuery: Click on a paragraph and add another paragraph

jQuery Fundamental - II : Exercise-75

Click on a paragraph and add another paragraph.

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>Click on a paragraph and add another paragraph.</title>
</head>
<body>
<p>Click me to add new paragraph.</p>
</body>
</html>

CSS Code :

 p {
 background: orange;
 font-weight: bold;
 cursor: pointer;
 padding: 5px;
 }
 

JavaScript Code :

$( "body" ).delegate( "p", "click", function() {
$( this ).after( "<p>New paragraph!</p>" );
});

See the Pen jquery-fundamental-exercise-75 by w3resource (@w3resource) on CodePen.


Contribute your code and comments through Disqus.

Previous: Animate the hiding and showing of two divs, delaying the first before showing it.
Next: End a custom queue function using dequeue which allows the queue to keep going.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.