w3resource
jquery exercises

jQuery: Appends a jQuery object to all paragraphs

jQuery Fundamental - I : Exercise-24

Using jQuery appends a jQuery object to all paragraphs.

<body>
<strong> Exercises</strong>  
<p>JavaScript</p>
<p>jQuery</p>
<button id="button1">Click to see the changes</button>   
</body>

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>Appends a jQuery object to all paragraphs.</title>
<style type="text/css">
button {
display: block;
margin: 20px 0 0 0;
 }   
 </style>
 </head>
 <body>
 <strong> Exercises</strong>
 <p>JavaScript</p>
 <p>jQuery</p>
 <button id="button1">Click to see the changes</button>
 </body>
 </html>

JavaScript Code :

$('#button1').click(function(){ 
$( "p" ).append( $( "strong" ) );
});

Used Methods :

  • .append() : Insert content, specified by the parameter, to the end of each element in the set of matched elements.

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


Contribute your code and comments through Disqus.

Previous: Using jQuery appends some text to all paragraphs.
Next: Using jQuery appends an Element to all paragraphs.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming