I was getting selectNode() param 1 is not of type node error.
changed the code to this and its working. (for chrome)
function copy_data(containerid) {_x000D_
var range = document.createRange();_x000D_
range.selectNode(containerid); //changed here_x000D_
window.getSelection().removeAllRanges(); _x000D_
window.getSelection().addRange(range); _x000D_
document.execCommand("copy");_x000D_
window.getSelection().removeAllRanges();_x000D_
alert("data copied");_x000D_
}
_x000D_
<div id="select_txt">This will be copied to clipboard!</div>_x000D_
<button type="button" onclick="copy_data(select_txt)">copy</button>_x000D_
<br>_x000D_
<hr>_x000D_
<p>Try paste it here after copying</p>_x000D_
<textarea></textarea>
_x000D_