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.
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.
<div id="demo"> <p>This is the text inside</p> </div>
Example 2: This example illustrates that the outerHTML DOM displays only the HTML element whose id is given and not its parent
<p id="demo">This is the text inside</p>
- How to change an HTML element name using jQuery ?
- How to check an HTML element is empty using jQuery ?
- How to select html element using ID in jQuery when ID contains a dot character ?
- How to get all HTML content from DOMParser excluding the outer body tag ?
- How to remove parent element except its child element using jQuery ?
- jQuery | Move an element into another element
- How to create a div element in jQuery ?
- How to get a DOM Element from a jQuery Selector ?
- How to get focused element using jQuery?
- How to change the element id using jQuery ?
- jQuery | element + next Selector
- jQuery | element Selector
- jQuery | Create a div element
- How to get all CSS styles associated with an element using jQuery ?
- How to select an element by name with jQuery?
- How to break an outer loop with PHP ?
- JQuery | Get the text of a span element
- How to check if an element is hidden in jQuery?
- How to check an element contains a class using jQuery?
- How to scroll to specific element using jQuery ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.