{"id":1330,"date":"2012-10-24T06:30:10","date_gmt":"2012-10-24T06:30:10","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=1330"},"modified":"2012-10-24T06:30:10","modified_gmt":"2012-10-24T06:30:10","slug":"jquery-wrap-iframe-wrap-iframe-in-div-using-jquery-examples","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/jquery-wrap-iframe-wrap-iframe-in-div-using-jquery-examples\/","title":{"rendered":"jQuery Wrap IFrame (in Div) Examples"},"content":{"rendered":"<p>While working with iframe (or with any other element), it might sometimes be desirable to have a complete control over it, such as it&#8217;s spacing, padding, alignment, etc. For the same reason, it can be very helpful to wrap the iframe (or the desired element) in a div, so that appropriate CSS styles can be applied to the div. In this article, I am going to share a very easy way to <em><strong>wrap iframe in div using jQuery<\/strong><\/em>. You can use this to <em><span style=\"text-decoration: underline;\"><strong>wrap video iframe or any other dynamically created elements in a div<\/strong><\/span><\/em>. Read on to find out more.<!--more--><\/p>\n<h2>Wrap IFrame in Div using jQuery<\/h2>\n<p>Let&#8217;s discuss how to <strong>wrap an element using a div<\/strong> in general first, so that you can use this technique and apply it to any element of your choice. So let&#8217;s say we have an element and we want to wrap it in a div. We can do it like so:<\/p>\n<h3>Example 1: Wrap an element using Div (in its most basic form)<\/h3>\n<pre class=\"lang:js decode:true\">$(element).wrap(\"&lt;div class='my_div'\/&gt;\");<\/pre>\n<h3>Example 2: Wrap an iframe using Div<\/h3>\n<pre class=\"lang:js decode:true\">$(\"iframe\").wrap(\"&lt;div class='my_div'\/&gt;\");<\/pre>\n<h3>Example 3: Wrap an object using Div<\/h3>\n<pre class=\"lang:js decode:true\">$(\"object\").wrap(\"&lt;div class='my_div'\/&gt;\");<\/pre>\n<h3>Example 4: Wrap a Div using Div (Using the ID of the div to be wrapped)<\/h3>\n<pre class=\"lang:js decode:true\">$(\"#my_first_div\").wrap(\"&lt;div class='my_div'\/&gt;\");<\/pre>\n<h3>Example 5: Wrap a Div using Div (Using the class of the div to be wrapped)<\/h3>\n<pre class=\"lang:js decode:true\">$(\".my_second_div\").wrap(\"&lt;div class='my_div'\/&gt;\");<\/pre>\n<h3>Example 6: Wrap a Table using Div<\/h3>\n<pre class=\"lang:js decode:true\">$(\"table\").wrap(\"&lt;div class='my_div'\/&gt;\");<\/pre>\n<h3>Example 7: Wrap a Div using Div and then wrap the resultant div with another div<\/h3>\n<pre class=\"lang:js decode:true\">$(\"#video\").wrap(\"&lt;div class='video_container'\/&gt;\");\n\n$(\".video_container\").wrap(\"&lt;div class='my_div'\/&gt;\");<\/pre>\n<h5>Simple, isn&#8217;t it?<\/h5>\n<p>Do you know of any other ways to <strong>wrap iframe in div using jQuery<\/strong>? Feel free to suggest by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While working with iframe (or with any other element), it might sometimes be desirable to have a complete control over it, such as it&#8217;s spacing, padding, alignment, etc. For the same reason, it can be very helpful to wrap the iframe (or the desired element) in a div, so that appropriate CSS styles can be [&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":[40,41],"class_list":["post-1330","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery-tips-and-tricks","category-tips-and-tricks","tag-jquery-2","tag-jquery-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-ls","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/1330","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=1330"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/1330\/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=1330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=1330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=1330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}