I want to build something like a Countdown, but not a countdown. I am actually sill learning and would appreciate any direction you can point me to.
I managed to accomplish this working code:
function getSelectionHtml() {
var html = "";
if (typeof window.getSelection != "undefined") {
var sel = window.getSelection();
if (sel.rangeCount) {
var container = document.createElement("div");
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
container.appendChild(sel.getRangeAt(i).cloneContents());
}
html = container.innerHTML;
}
} else if (typeof document.selection != "undefined") {
if (document.selection.type == "Text") {
html = document.selection.createRange().htmlText;
}
}
console.log(html);
// Split every word and separate them by a comma
var split = html.split(" ");
console.log(split);
confirm(split);
}
What it does is, that it gets a selected/highlighted Numbers and presents them to the reader. But I actually want to do stuff with it first, with the highlighted Numbers.
I want them to be displayed in a new DIV one after the other. Let say I highlight 1 to 10 and after I click the button, a Div Tag should show up with the Number 1, after that the Number 2 and so on, Until I reached the Number 10.
Any help? Unfortunately my jsfidle isn't working and I don't know why. Thank you in advance.
EDIT: I figured out by adding:
var array = split;
console.log(array);
That I can put the seleciton into an array. Now I have to figure out how to loop them to be displayed one after another in a separate new div.