Есть блок в который через бекенд передается значение
<div id="tech-inf" class="tech_info" data-help="Select to copy">
{{ pw.account_info_config|tojson }}
как сделать на js или jquery что бы я смог по нажатию на блок скопировать тект который приходит мне?
$("#tech-inf").click(function () {
CopyToClipboard('info_tech');
});
function copyToClipboard(elementId) {
// Create a "hidden" input
var aux = document.createElement("input");
// Assign it the value of the specified element
aux.setAttribute("value", document.getElementById(elementId).innerHTML);
// Append it to the body
document.body.appendChild(aux);
// Highlight its content
aux.select();
// Copy the highlighted text
document.execCommand("copy");
// Remove it from the body
document.body.removeChild(aux);
}
так не работает(
function copyToClipboard(elementId) {
// Create a "hidden" input
var aux = document.createElement("input");
// Assign it the value of the specified element
aux.setAttribute("value", document.getElementById(elementId).innerHTML);
// Append it to the body
document.body.appendChild(aux);
// Highlight its content
aux.select();
// Copy the highlighted text
document.execCommand("copy");
// Remove it from the body
document.body.removeChild(aux);
console.log(document.
}
$("#tech-inf").click(function () {
copyToClipboard('tech-inf');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="tech-inf" class="tech_info" data-help="Select to copy">
{{ pw.account_info_config|tojson }}
</div>
Сборка персонального компьютера от Artline: умный выбор для современных пользователей