How to convert HTML content into it's constituent entities in JQuery
14:18 11 Feb 2026

There is a DIV containing a bunch of HTML.

We want on a certain event in JQuery 3.7.1, to have that contents of that div turned into its core entities:

Hello

Becomes :

<p>Hello</p>

We have been told that .html() does this, but it appears to specifically not do this as we need.

    $('#button').on("click", function(){
        $('pre#output').text($('#thediv').html());
    });


Hello Word

...

Above you will see the output is

Hello Word

but it should be <p>Hello <strong>Word</strong></p>

How can we reach this end in JQuery 3.7.1?

jquery