Languages
[Edit]
EN

JavaScript - how to get outer html?

6 points
Created by:
Root-ssh
6417

Using JavaScript it is possible to get outer html source code in following ways.

1. outerHTML property example

// ONLINE-RUNNER:browser;

<html>
<body>
  <div id="element">
    <h3>Head 1</h3>
    <p>Some apostrophe text...</p>
    <h3>Head 2</h3>
    <p>Some apostrophe text...</p>
  </div>
  <script>

    var element= document.getElementById('element');

    console.log(element.outerHTML);

  </script>
</body>
</html>

2. jQuery example

How to get outerHTML with jQuery has been described in this article.

See also

  1. JavaScript - what is difference between inner and outer html?
  2. jQuery - how to get outer html?

Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.