JQuery: Append A Div Element (and All Of Its Contents) Dynamically To ...

jQuery: Append a div element with all contents dynamically to the body element Last update on July 23 2025 12:33:15 (UTC/GMT +8 hours)

jQuery core : Exercise-6 with Solution

Write jQuery code to append a div element (and all of its contents) dynamically to the body element.

Insert the following code within HTML <body> tag :

<div><h1>JQuery Core</h1></div>

Solution :

HTML Code :

<!DOCTYPE html> <html> <head> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <meta charset="utf-8"> <title>Append a div element (and all of its contents) dynamically to the body element</title> </head> <body> </body> </html>

JavaScript Code :

$( "<div><h1>JQuery Core</h1></div>" ).appendTo( "body" );

Go to:

  • jQuery Core Exercises Home ↩
  • jQuery Exercises Home ↩

PREV : Check/uncheck a checkbox input or radio button. NEXT : Write a jQuery Code to get a single element from a selection.

Live Demo:

See the Pen jquery-core-exercise-6 by w3resource (@w3resource) on CodePen.

Contribute your code and comments through Disqus.

Tag » Add Element Jquery To Div