How to create a div using jQuery with style tag ? Last Updated : 28 Apr, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Creating an <div> element with a style tag using jQuery can be done in the following steps. Steps: Create a new <div> element.Create an object with all the styles that we want to apply.Choose a parent element, where to put this newly created element.Put the created div element into the parent element. Example 1: This example will create an <div> element and use the append() method to append the element at the end of the parent element. HTML <!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-git.js"> </script> <style> .divClass { height: 40px; width: 200px; border: 1px solid blue; color: white } </style> </head> <body> <h2 style="color:green">GeeksforGeeks</h2> <div id="parent"> This is parent div </div> <div style="height:10px;"></div> <!-- JavaScript function addText() is called to add to parent div--> <input type="button" value="Add <div> Text" onclick="addText()" /> <script> <!-- Function to add text in a div element with above styles--> function addText() { $(document).ready(function() { var object = { id: "divID", class: "divClass", css: { "color": "Red" } }; var addition = $("<div>", object); addition.html("Added text GFG"); $("#parent").append(addition); }); } </script> </body> </html> Output: append Example 2: This example will create an <div> element and uses the prependTo() method to append the element at the start of the parent element. HTML <!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-git.js"> </script> <style> .divClass { height: 40px; width: 200px; border: 1px solid blue; color: white } </style> </head> <body> <h2 style="color:green">GeeksforGeeks</h2> <div style="height:10px;"></div> <div id='parent'> This is parent div </div> <div style="height:10px;"></div> <input type="button" value="Prepend text div " onclick="prependDiv()" /> <script> function prependDiv() { $(document).ready(function() { var object = { id: "divID", class: "divClass", css: { "color": "Red" } }; <!--Prepend object is created before the parent div--> var prependObject = $("<div>", object); prependObject.html("Prepend text is GFG"); $(prependObject).prependTo($('#parent')); }); } </script> </body> </html> Output: Prepend text Comment More infoAdvertise with us Next Article How to create a div using jQuery with style tag ? K KapilChhipa Follow Improve Article Tags : Web Technologies JQuery jQuery-Methods jQuery-Questions Similar Reads How to Create a Style Tag using JavaScript? To create a <style> tag using JavaScript, use the document.createElement() method to create the tag, which allows you to dynamically add elements to the DOM.Syntaxdocument.createElement('style')Example 1: This HTML code dynamically styles a <div> element with a green background and white 1 min read How to set border width using jQuery ? In this article, we will see how to set the border width using jQuery. To set the border width using jQuery, we will use css() method. This method is used to change the style property of the selected element. Syntax: $(selector).css(property, value) // Or $(selector).css({property: value, property: 2 min read How to apply CSS style using jQuery ? In this article, we will explore how we can apply CSS styles to HTML elements. It is recommended that you have some basic knowledge of HTML, CSS, JavaScript, and jQuery before beginning this article. It is possible to change the CSS property of an element by using a simple JavaScript API, but we try 2 min read How to get styles of a clicked division using jQuery ? In this article, we will learn how to get the styles (width, height, text color, and background color) of a clicked division using jQuery. Approach: The css() method is used to get the CSS property values of the selected element in jQuery. We use the css() method in jQuery that takes an array of nam 2 min read How to Wrap an Element with Another Div Using jQuery? We will see how to wrap an element with another div in jQuery. We will simply wrap an element inside a div tag in jQuery. These are the following approaches: Table of Content Using wrap() method Using wrap.inner() methodApproach 1: Using wrap() method We include the jQuery library in the <head 3 min read Like