jQuery: Create a paragraph element with some text and append it to the end of the document
jQuery Fundamental - I : Exercise-3
Create a paragraph element with some text and append it to the end of the document body using jQuery.
Sample solution :
<!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>Create a paragraph element with some text and append it to the end of the document body using jQuery.</title> </head> <body> <p>jQuery</p> </body> </html>
$( "p" ).add( "<span>Exercises</span>" ).appendTo( document.body );
Used Methods :
- .add(elements) : Create a new jQuery object with elements added to the set of matched elements.
- .appendTo() : Insert content, specified by the parameter, to the end of each element in the set of matched elements.
Contribute your code and comments through Disqus.
What is the difficulty level of this exercise?
Many of our valued users post comments along with piece of code. Disqus may, false positively, consider those piece of code as Bad or Starnge syntax and send those comments to spam automatically. Even if that happens, we will make sure those useful comments are taken out of spam and approved. It may take a couple of days for that though, but any useful comment will be brought to public view for sure. We regret if that happend to any user. You may write us directly regarding this to - w3resource[at]yahoo[dot]com.