Using First part of following solution I am able to copy value of the input into clipboard. but can you please let me know how about copying HTML like a entire <p>? As you can see I am getting
copyHTML.select is not a function
can you please let me know if this is doable in JS and how I can fix this?
$("#copy").on("click", function(){
var copyText = document.getElementById("myInput");
copyText.select();
document.execCommand("Copy");
alert("Copied the text: " + copyText.value);
});
$("#copyHTML").on("click", function(){
var copyHTML = document.getElementById("sample");
copyHTML.select();
document.execCommand("Copy");
alert("Copied the text: " + copyHTML.HTML);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" value="Hello World" id="myInput">
<button id="copy">Copy text</button>
<p id="sample" class="napper">This is atest Paragraph</p>
<button id="copyHTML">Copy HTML</button>
.outerHTMLproperty?