I'd like to parse the text copied by Clipboard.js
and set it again to the Clipboard.
$(document).ready(function () {
function addTableLines(originaltext) {
result = '';
var lines = originaltext.split('\n');
console.log(lines);
for (var i = 0; i < lines.length; i++) {
var str = lines[i];
console.log(str);
var replaced = str.split(' ').join(' | ');
replaced = replaced + '<br> ------- <br>';
result += replaced;
}
return result;
}
new Clipboard('.clipboard-btn', {
text: function (trigger) {
var originaltext = $(trigger).next("orders-tbl").text();
console.log(originaltext); // is empty
return addTableLines(originaltext);
}
});
});
The originaltext
is always empty, what's wrong with my implementation ?
Update, solution was:
var originaltext = $(trigger).next('table').closest("#orders-tbl").text();