jQuery: Insert a DOM elements after all paragraphs
jQuery Fundamental - I : Exercise-9
Using jQuery insert a DOM element after all paragraphs.
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>Using jQuery insert a DOM element after all paragraphs.</title>
<style type="text/css">
button {
display: block;
margin: 20px 0 0 0;
} </style>
</head>
<body>
<p>jQuery Exercises</p>
<button id="button1">Click to see the effect</button>
</body>
</html>
JavaScript Code :
$('#button1').click(function(){
$( "p" ).after( document.createTextNode( "with solution." ) );
});
Used Methods :
- .after() : Insert content, specified by the parameter, after each element in the set of matched elements.
See the Pen jquery-fundamental-exercise-9 by w3resource (@w3resource) on CodePen.
Contribute your code and comments through Disqus.
Previous: Using jQuery insert some HTML after all paragraphs.
Next: Using jQuery insert a jQuery object (similar to an Array of DOM Elements) after all paragraphs.
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://www.w3resource.com/jquery-exercises/1/jquery-fundamental-exercise-9.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics