How to get the outer html of an element using jQuery ? Last Updated : 15 Feb, 2023 Comments Improve Suggest changes Like Article Like Report 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 the above to get the value of the outer HTML element. Below is an example that illustrates how to fetch the outer HTML element of an HTML element and store it in a variable newVar. Example 1: In this example, it has a div that encloses a paragraph with id = "demo". When the on-screen button is pressed the JavaScript pushes an alert message on the browser window with the outer HTML of the HTML element with the given id. HTML <div id="demo"> <p>This is the text inside</p> </div> <button onclick="myFunction()">Try it</button> <p id="gfg"></p> <script> function myFunction() { var newVar = document.getElementById("demo") .outerHTML; document.getElementById("gfg").innerHTML = newVar; } </script> Output: How to get the outer html of an element using jQuery ? Example 2: This example illustrates that the outerHTML DOM displays only the HTML element whose id is given and not its parent HTML <div> <p id="demo">This is the text inside</p> </div> <p id="gfg"></p> <button onclick="myFunction()">Try it</button> <script> function myFunction() { var newVar = document.getElementById("demo") .outerHTML; document.getElementById("gfg").innerHTML = newVar; } </script> Output: How to get the outer html of an element using jQuery ? Comment More infoAdvertise with us Next Article How to get the outer html of an element using jQuery ? S suchetaggarwal4 Follow Improve Article Tags : Web Technologies JQuery How To jQuery-Questions Similar Reads How to get title of current HTML page using jQuery ? Suppose you have given an HTML page and the task is to get the title of an HTML page with the help of only jQuery. There are two approaches that are discussed below: Approach 1: The $('title') jQuery selector is used to select the title element of the document and we can use text() method on the sel 2 min read How to attach a method to HTML element event using jQuery ? In this article, we are going to learn, how can we attach a method to an HTML element event using jQuery.There are various events like click(), mouseenter(), mouseout(), etc which are available in jQuery. For attaching a method to an HTML elements event, we will need a jQuery method on(), which will 2 min read How to get text contents of all matched elements using jQuery ? In this article, we will see how to get the text content of all matched class elements using jQuery. To get the text content, we use the text() method, which helps to set or return the text content of the element. Syntax: $('Selector').text();Approach 1: We create a div element that contains multipl 2 min read How to get the text without HTML element using JavaScript ? Given an HTML document containing some elements and the task is to get the text inside an HTML element using JavaScript. There are two methods to get the text without HTML element which are listed below: Using innerText propertyUsing textContent property Using innerText property: We can use innerTex 1 min read How to Get the Content of an HTML Comment using JavaScript ? In this article, we will learn how to get the content of an HTML Comment Using Javascript. Comments are a best practice in programming and software development. In general, they can explain why a coding decision was made or what needs to be done to improve the code you're working on. HTML tags (incl 3 min read How to Get the Width of Hidden Element in jQuery? An HTML element can be hidden with the help of the .hide() jQuery function or we can hide easily by making visibility equals hidden in CSS. We can easily find the width of this hidden element in jQuery.Two kinds of width are defined with every HTML element i.e, innerWidth and the outerWidth of the e 3 min read How to get the child element of a parent using JavaScript ? Given an HTML document, the task is to select a particular element and get all the child elements of the parent element with the help of JavaScript. Below are the approaches to get the child element of a parent using JavaScript:Table of ContentBy using the children propertyBy using the querySelector 3 min read How to find the class of clicked element using jQuery ? In this article, we will find the class of the clicked element using jQuery. To find the class of clicked element, we use this.className property. The className property is used to set or return the value of an elementâs class attribute. Using this property, the user can change the class of an eleme 1 min read How to get inner width (excluding the border) of an element using jQuery ? We can get the inner width of any element using the jQuery innerWidth() method. The innerWidth() method returns the inner width of the first matched element including padding but not border. Syntax: $(selector).innerWidth() So the inner width of an element is shown in the below image. Inner width Th 1 min read How to select all sibling elements of an element using jQuery ? In this article, we will discuss how to select all sibling elements of an element using jQuery. To select all sibling elements of an element, we will use the siblings() method. The siblings() method is used to find all sibling elements of the selected element. The siblings are those having the same 2 min read Like