I'm new to programming & I was building this to help me aid copy pasting common notes & content, which I have to do a lot at my work. Kindly check the program here https://jsbin.com/ruvodipomi/edit?html,js,output
<html>
<button onclick="copyToClipboard('#p1')">Hello</button><br>
<p id="p1">Hello<br> World</p>
<textarea cols="80" rows="25"></textarea>
</html>
<script>
function copyToClipboard(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();
}
</script>
So, if you click on the button 'Hello', it saves 'Hello World' in the clipboard. In this way I can make multiple buttons containing number of notes, which would make my work easier, instead of copying them from some document.
The problem is,
I'm unable to break line in the elements
For e.g.
Instead of saving 'Hello World' in clipboard,
I wish to save
'Hello
World'
However I'm unable to do so by using <br> <br /> <\n>
It is very important for the program to process breaks or at least accept them through tags.
I believe it has something to do with the Java function? But I'm not getting it.
Could you please have a look? Thanks so much^^