Paul Stevens Paul Stevens - 8 months ago 37
HTML Question

Remove unwanted tags from clipboard

I have a function which is successfully returning a ul list of random numbers between 1 and 100, and it places the numbers on the user's clipboard. This is just for IE but this isn't a problem.
This issue is that the resulting text on the clipboard is retaining the li tags like below. Is there a way to remove these tags from the data before it hits the clipboard?


The JS code:

function ReturnRandomNumbers() {
var howManyInt = parseInt(document.getElementById("txtMultiples").value);
var listNumbers = document.getElementById("listNumbers");
var i = 0;

if (howManyInt < 101 && howManyInt > 0) {
listNumbers.innerHTML = "";
while (i < howManyInt) {

} else {
alert("Value must be between 1 and 100");

function AddItemToList(item) {
var ol = document.getElementById("listNumbers");
var li = document.createElement("li");

var str = "<LI>68</LI>\n<LI>97</LI>\n<LI>94</LI>\n<LI>43</LI>\n<LI>45</LI>\n<LI>65</LI>"


var str = listNumbers.innerHTML;

You want to strip the li tags from the string, you can do a regex match and replace

var stripped = str.replace(/</*LI>/g,'');

Which will give

"68 97 94 43 45 65"

Pass it to your clipboard window.clipboardData.setData("text",stripped);