JSFiddle - React, Tailwind, and code Playground

HTML

<button id="click">Highlight</button>
<iframe id="iframe" width="300px" height="300px" />

JavaScript

$(document).ready(function () {
    $('#iframe').contents().find('body').html('<p>Line 1</p><p>Line 2</p>');

    $('#click').click(function () {
        var iframe = $('#iframe')[0];
        
        var doc = iframe.contentDocument;
        doc.execCommand('selectAll');
        
        try {
           var successful = doc.execCommand('copy');
           var msg = successful ? 'successful' : 'unsuccessful';
            console.log('Copying text command was ' + msg);
        } catch (err) {
            console.log('Oops, unable to copy');
        }
    });
});