{"id":2727,"date":"2013-03-10T10:05:59","date_gmt":"2013-03-10T10:05:59","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=2727"},"modified":"2013-03-10T10:05:59","modified_gmt":"2013-03-10T10:05:59","slug":"using-jquery-add-remove-div-easy-examples-to-add-content-to-div","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/using-jquery-add-remove-div-easy-examples-to-add-content-to-div\/","title":{"rendered":"jQuery Add Remove Div Examples"},"content":{"rendered":"<p>Div\u00a0manipulation\u00a0is very helpful,\u00a0especially\u00a0when you are dealing with dynamic data. That said, to know how to add a div and\/or to remove that div? If not, don&#8217;t worry. In this article, I am going to share with you, easy ways to use <em><strong>jQuery to\u00a0add and to remove div<\/strong><\/em>\u00a0by means of easy examples. So follow along to find out more.<\/p>\n<p><!--more--><\/p>\n<h2>How to use jQuery to Add Remove Div<\/h2>\n<div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=2727\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    \n<p>Let&#8217;s assume that we have a div with ID \u00a0&#8220;my_div1&#8221; in it. We would now like to add a div to this &#8220;my_div1&#8221;. The following example shows you how to do it easily:<\/p>\n<h3>Example &#8211; Add div &amp; remove added div using jQuery<\/h3>\n<pre class=\"lang:xhtml decode:true\" title=\"Example\">&lt;class&gt;\n&lt;head&gt;\n&lt;title&gt;Examples to Add a Div and Remove a Div using jQuery&lt;\/title&gt;\n&lt;script type=\"text\/javascript\" src=\"js\/jquery-1.8.2.min.js\"&gt;&lt;\/script&gt;\n&lt;style type=\"text\/css\"&gt;\n#my_div1 {\n\tbackground-color: #E1F3FF;\n\tborder: 1px solid #09F;\n\tpadding: 10px;\n\tmargin-bottom: 10px;\n}\n#my_div2 {\n\tbackground-color: #9999FF;\n\tborder: 1px solid #90F;\t\n\tpadding: 10px;\n\tmargin-bottom: 10px;\t\n}\n&lt;\/style&gt;\n&lt;\/head&gt;\n\n&lt;body&gt;\n\n&lt;div id=\"my_div1\"&gt;This is MY DIV 1&lt;\/div&gt;\n\n&lt;p&gt;\t\n&lt;input type=\"submit\" name=\"sbt_add2div1\" id=\"sbt_add2div1\" value=\"Add New Div to MY DIV 1\"&gt;\n\n&lt;input type=\"button\" name=\"sbt_reset\" id=\"sbt_reset\" value=\"Remove New Div from MY DIV 1\"&gt;\n&lt;\/p&gt;\n\n&lt;script type=\"text\/javascript\" language=\"javascript\" &gt;\n\n$(document).ready(function(){\n\n\t\/\/This will add div to MY DIV 1\n\t$('#sbt_add2div1').on(\"click\", function(e){\t\t\n\n\t\t$('&lt;div id=\"my_div2\" class=\"some_class\"&gt;This is MY DIV 2&lt;\/div&gt;').appendTo('#my_div1');\n\n\t\te.preventDefault();\n\n\t});\t\n\n\t$('#sbt_reset').on(\"click\", function(e){\n\n\t\t$(\"#my_div2\").remove();\n\n\t\te.preventDefault();\n\n\t});\t\t\n\n});\t\n\n&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/class&gt;<\/pre>\n<div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=2727\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    \n<h4>Simple, isn&#8217;t it?<\/h4>\n<p>Do you know of any other ways to use \u00a0<em><strong>\u00a0jQuery to add remove div<\/strong><\/em>? Feel free to suggest by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Div\u00a0manipulation\u00a0is very helpful,\u00a0especially\u00a0when you are dealing with dynamic data. That said, to know how to add a div and\/or to remove that div? If not, don&#8217;t worry. In this article, I am going to share with you, easy ways to use jQuery to\u00a0add and to remove div\u00a0by means of easy examples. So follow along to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":395,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[20,13],"tags":[42,43,41],"class_list":["post-2727","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery-tips-and-tricks","category-tips-and-tricks","tag-jquery-demos-2","tag-jquery-snippets","tag-jquery-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-HZ","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/2727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/comments?post=2727"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/2727\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/media?parent=2727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=2727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=2727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}