js copy
В примере по клику на i
в блоке .link
скопировать ссылку внутри этого блока
function copyToClipboard(textToCopy){ if(navigator.clipboard&&window.isSecureContext){ return navigator.clipboard.writeText(textToCopy); } else{ let textArea=document.createElement("textarea"); textArea.value=textToCopy; textArea.style.position="fixed"; textArea.style.left="-999999px"; textArea.style.top="-999999px"; document.body.appendChild(textArea); textArea.focus(); textArea.select(); return new Promise((res,rej)=>{ document.execCommand('copy')?res():rej(); textArea.remove(); }); } } $(document).ready(function(){ $('.link i').on('click',function(){ var link=$(this).closest('.link').find('a').attr('href'); copyToClipboard(link).then(()=>console.log('copied')).catch(()=>console.log('not copied')); }); });