Languages
[Edit]
EN

JavaScript - how to get outer html?

6 points
Created by:
Root-ssh
85410

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
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join