How to insert HTML content into an iFrame using jQuery? Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Here is the task to insert HTML content into an iFrame using jQuery. To do so, we can use the jQuery contents() method. The .contents() method: It returns all the direct children, including text and comment nodes for the selected element. Syntax: $(selector).contents()Find the iframe in the body section.Get the value to be inserted in the iframe in the body sectionPlace the value in the iframe jQuery code to show the working of this approach: Example 1: html <script src= "https://code.jquery.com/jquery-1.12.4.min.js"> </script> <style type="text/css"> textarea, iframe { display: block; margin: 10px 0; } iframe { width: 500px; border: 1px solid #000000; } </style> <h1 style="color:green;"> GeeksforGeeks </h1> <h3> How to insert HTML content into an iFrame using jQuery </h3> <textarea rows="2" cols="40" style="text-align:center;"> GEEKSFORGEEKS - A computer science portal for geeks. </textarea> <button type="button" onclick="updateIframe()"> Click to Insert </button> <iframe style="text-align:center;" id="myframe"></iframe> <script type="text/javascript"> function updateIframe() { var myFrame = $("#myframe").contents().find('body'); var textareaValue = $("textarea").val(); myFrame.html(textareaValue); } </script> Output: Example 2: html <script src="https://code.jquery.com/jquery-1.12.4.min.js"> </script> <style type="text/css"> iframe { width: 500px; border: 1px solid #000000; } </style> <h1 style="color:green;"> GeeksForGeeks </h1> <h3>How to insert HTML content into an iFrame using jQuery</h3> <h4>Text to be insert : "GEEKSFORGEEKS - A computer science portal for geeks."</h4> <iframe style="text-align:center;" id="iframe"> </iframe> <script> $("#iframe").ready(function() { var body = $("#iframe").contents().find("body"); body.append( 'GEEKSFORGEEKS - A computer science portal for geeks.'); }); </script> Output: Comment More infoAdvertise with us Next Article How to specify name of an iframe element using HTML ? S SHUBHAMSINGH10 Follow Improve Article Tags : Web Technologies JQuery jQuery-Questions Similar Reads How to get HTML content of an iFrame using JavaScript ? The <iframe> tag specifies an inline frame. It allows us to load a separate HTML file into an existing document. Code snippet:function getIframeContent(frameId) { let frameObj = document.getElementById(frameId); let frameContent = frameObj. contentWindow.document.body.innerHTML; alert("frame c 1 min read How to specify name of an iframe element using HTML ? The iframe in HTML stands for Inline Frame. The "iframe" tag defines a rectangular region within the document in which the browser can display a separate document, including scrollbars and borders. An inline frame is used to embed another document within the current HTML document. The HTML iframe na 1 min read How to set height of an iframe element using HTML ? The iframe in HTML stands for Inline Frame. The "iframe" tag defines a rectangular region within the document in which the browser can display a separate document, including scrollbars and borders. An inline frame is used to embed another document within the current HTML document. The HTML <ifram 1 min read How to create an HTML element using jQuery ? In this article, we will see how to create an HTML element using jQuery. To create and append the HTML element, we use the jQuery append() method. The jQuery append() method is used to insert some content at the end of the selected elements. Syntax: $(selector).append( content, function(index, html) 2 min read How to Load an HTML File into Another File using jQuery? Loading HTML files into other HTML files is a common practice in web development. It helps in reusing HTML components across different web pages. jQuery is a popular JavaScript library, that simplifies this process with its .load() method. Approach 1: Basic Loading with .load() MethodThe .load() met 2 min read How to get the outer html of an element using jQuery ? Sometimes, there is a need to get the entire HTML element by its id and not merely its contents, for doing so, we shall use the HTML DOM outerHTML Property to get the outer HTML of HTML element. Syntax: document.getElementById("your-element-id").outerHTML) You can use a variable and initialize it to 2 min read Like