Languages
[Edit]
EN

JavaScript - how to get outer html?

6 points
Created by:
Root-ssh
68980

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?

Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join