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 Hide an HTML Element in Mobile View using jQuery ?
- How to remove parent element except its child element using jQuery ?
- jQuery | Move an element into another element
- How to break an outer loop with PHP ?
- How to select an element by name with jQuery?
- How to get all CSS styles associated with an element using jQuery ?
- How to create a div element in jQuery ?
- jQuery | element Selector
- How to get focused element using jQuery?
- How to change the element id using jQuery ?
- jQuery | element + next Selector
- jQuery | Create a div element
- How to get a DOM Element from a jQuery Selector ?
- How to scroll to specific element using jQuery ?
- How to make an element “flash” in jQuery ?
- How to find which DOM element has the focus 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 firstname.lastname@example.org. 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.