There are various method to create HTML element inside an HTML document using JQuery. But the simplest of all is append() and prepend() method.
Method 1: Using prepend() Method: The prepend() method is used to insert a specified content at the beginning of the selected element.
Example: This example uses prepend() method to create div element at the beginning of selected element.
Method 2: Using appendTo() Method: The appendTo() method in jQuery is used to insert HTML element at the end of the selected element.
Example 1: This example uses appendTo() method to create div element at the end of selected element.
Example 2: This example uses appendTo() method to create div element within the div element.
- How to copy the content of a div into another div using jQuery ?
- jQuery | Create a div element
- How to overlay one div over another div using CSS
- How to center a div within another div?
- How to clear all div's content inside a parent div ?
- How to hide div element after few seconds in jQuery ?
- How to dynamically set the height and width of a div element using jQuery ?
- How to replace innerHTML of a div using jQuery?
- How to hide a div when the user clicks outside of it using jQuery?
- How to fadeOut and remove a div using jQuery ?
- How to animate div width and height on mouse hover using jQuery ?
- How to display div elements using Dropdown Menu in jQuery?
- How to detect and change the content/style of a div using jQuery ?
- How to select a div with a certain class using jQuery ?
- How to iterate through child elements of a div using jQuery ?
- How to create three boxes in the same div using HTML and CSS ?
- Display div element on hovering over <a> tag using CSS
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Shivam_k