How does js select text from multiple dom and copy it to the clipboard together?

refers to a similar question raised by a big shot earlier: https://codeshelper.com/q/10.
found that if there are multiple elements, only the text in the last element will be retained.
my idea is to first select the text to be copied one by one, and finally copy it together, but without success. Google browser for
.

the failed code is as follows:
for (let i = 0; I < $("input:checked"). Parent (). Next (). Children (). Length; iPP) {
var text = $("input:checked"). Parent (). Next (). Children () [I]
var selection = window.getSelection ()
var range = document.createRange ()
range.selectNodeContents (text)
selection.removeAllRanges () / / do not understand the meaning here, if you delete this sentence, it will not be copied directly. But if you don"t delete it, it feels like it will be emptied every time, so you can"t copy multiple lines.
selection.addRange (range)
}
document.execCommand ("Copy","false",null)

requirements: copy the text of all eligible elements to the clipboard and keep the formatting (line wrapping)
if there are other ways to achieve this requirement, please let me know
Thank you!

Mar.21,2021

https://github.com/zenorocha/.

new ClipboardJS('.btn', {
    text: function(trigger) {
        return 'You wanted'
    }
});

if you want to use native code, you can visit clipboard directly. This idea is simple: listen to copy events directly and add the content you want to copy directly.

https://codeshelper.com/a/11.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b7ef-2c28e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b7ef-2c28e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?