jQuery parseHTML() example

jQuery parseHTML() function is used to parses a string into an array of DOM nodes.


jQuery.parseHTML( data [, context ] [, keepScripts ] )
  • data - HTML string to be parsed 
  • context (default: document) - Document element to serve as the context in which the HTML fragment will be created 
  • keepscripts (default: false) - A Boolean indicating whether to include scripts passed in the HTML string


Create an array of DOM nodes using an HTML string and insert it into a div.
<!doctype html>
<html lang="en">

    <meta charset="utf-8">
    <title>jQuery.parseHTML demo</title>
    <script src="https://code.jquery.com/jquery-3.4.1.js"></script>


    <div id="log">

        var $log = $("#log"),
            str = "hello, <b>my name is</b> jQuery.",
            html = $.parseHTML(str),
            nodeNames = [];

        // Append the parsed HTML

        // Gather the parsed HTML's node names
        $.each(html, function(i, el) {
            nodeNames[i] = "<li>" + el.nodeName + "</li>";

        // Insert the node names
        $log.append("<h3>Node Names:</h3>");


Try it Yourself - Copy paste code in Online HTML Editor to see the result