{"id":2583,"date":"2013-03-04T14:16:14","date_gmt":"2013-03-04T14:16:14","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=2583"},"modified":"2013-03-04T14:16:14","modified_gmt":"2013-03-04T14:16:14","slug":"using-jquery-add-image-to-div-easy-examples-to-add-image-to-div","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/using-jquery-add-image-to-div-easy-examples-to-add-image-to-div\/","title":{"rendered":"jQuery Add Image To Div Examples"},"content":{"rendered":"<p>If you have followed my articles on how to add to div, then this task of adding an image to a div using jQuery<strong><\/strong><em><strong>\u00a0<\/strong><\/em>should be a no-big deal for you. In this article, I am going to share very easy way to use <strong><em>jQuery to\u00a0add image to div<\/em> <\/strong>by means of simple to follow examples.<\/p>\n<p><!--more--><\/p>\n<h2>How to use jQuery to Add Image to 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=2583\" 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>There are 2 ways to do this:<\/p>\n<ol>\n<li>Add image before the content of the div begins.<\/li>\n<li>Add image after the content of the div ends.<\/li>\n<\/ol>\n<p><strong>In both the above cases, the image will become a part of the div i.e. the image will be inside of the div<\/strong>. That said, let&#8217;s see how we can append an image to a div practically by means of examples.<\/p>\n<h3>Example 1 &#8211; Add image before the content of the div begins<\/h3>\n<pre class=\"lang:xhtml decode:true\" title=\"Example 1\">&lt;div id=\"my_div\"&gt;This is MY DIV&lt;\/div&gt;\n\n&lt;input type=\"submit\" name=\"sbt_add_before_content\" id=\"sbt_add_before_content\" value=\"Adding Image to Div BEFORE CONTENT\"&gt;\n\n\t\/\/This will result in addition of an image to a div before the content of the div has started\n\t$('#sbt_add_before_content').on(\"click\", function(e){\t\t\n\n\t\t$('#my_div').prepend('&lt;img id=\"my_img1\" src=\"images\/success.gif\" \/&gt;')\n\n\t\te.preventDefault();\n\n\t});<\/pre>\n<h3>Example 2 &#8211; Add image after the content of the div ends<\/h3>\n<pre class=\"lang:xhtml decode:true crayon-selected\" title=\"Example 2\">&lt;div id=\"my_div\"&gt;This is MY DIV&lt;\/div&gt;\n\n&lt;input type=\"submit\" name=\"sbt_add_after_content\" id=\"sbt_add_after_content\" value=\"Adding Image to Div AFTER CONTENT\"&gt;\n\n\t\/\/This will result in addition of an image to a div after the content of the div has ended\n\t$('#sbt_add_after_content').on(\"click\", function(e){\t\t\n\n\t\t$('#my_div').append('&lt;img id=\"my_img2\" src=\"images\/success.gif\" \/&gt;')\n\n\t\te.preventDefault();\n\n\t});<\/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=2583\" 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>Conclusion:<\/h4>\n<p>1. Use\u00a0.prepend() method if you wish to add image <strong>before<\/strong> the content of the div.<\/p>\n<p>2.\u00a0Use .append() method if you wish to add image <strong>after<\/strong> the content of the div.<\/p>\n<h4>Your Turn!<\/h4>\n<p>Do you know of any other ways to use<em><strong>\u00a0jQuery to add image to div<\/strong><\/em>? Feel free to share by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have followed my articles on how to add to div, then this task of adding an image to a div using jQuery\u00a0should be a no-big deal for you. In this article, I am going to share very easy way to use jQuery to\u00a0add image to div by means of simple to follow examples.<\/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-2583","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-FF","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/2583","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=2583"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/2583\/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=2583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=2583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=2583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}