jQuery: Appends an element to all paragraphs

jQuery Fundamental - I : Exercise-25

Using jQuery appends an Element to all paragraphs.

<button id="button1">Click to see the changes</button>   

Sample solution :

HTML Code :

<!DOCTYPE html>
<script src="https://code.jquery.com/jquery-git.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Appends an Element to all paragraphs.</title>
<style type="text/css">
button {
display: block;
margin: 20px 0 0 0;
   <button id="button1">Click to see the changes</button>

JavaScript Code :

$( "p" ).append( document.createTextNode( " Exercises" ) );

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-25 by w3resource (@w3resource) on CodePen.

Contribute your code and comments through Disqus.

Previous: Using jQuery appends a jQuery object to all paragraphs.
Next: Using jQuery append all spans to the element with specified id.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

Share this Tutorial / Exercise on : Facebook and Twitter