0

I want to take the innerhtml of a dynamically created div and put it in the clipboard but I keep getting a Type error. i want to access the .shortened div but I cant do it and I need help

const results = document.createElement('div')
// call api
function result(url){
    fetch(https://api.shrtco.de/v2/shorten?url=${url})
    .then(res => res.json())
    .then(data =>{
        if (data.ok){
        var data= data
        results.innerHTML = <div class="result">
        <div class="sent">${data.result.original_link}</div>
        <div class="shortened" id="short"><div>${data.result.short_link}</div>
        <div class="copy-wrapper"></div><a href="#" class="copy" onClick= "copyLink()">Copy</a></div>
        </div>
        // create div 
        answer.appendChild(results)
    }else {
        alert('incorrect url')

    }
    mainBtn.innerHTML = "Shorten it!"
 
    })
    
   
 }
femizi
  • 15
  • 1
  • 4

1 Answers1

0

Why need to access the innerHTML, when you can put the shortened URL directly to the copyLink function parameter?

<div class="copy-wrapper">
    <a href="#" class="copy" onClick="copyLink('${data.result.short_link}')">Copy</a>
</div>
Jose Lora
  • 1,392
  • 4
  • 12
  • 18
Lima
  • 257
  • 1
  • 8