Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

251
Visualizações
Adding a link to Idiomatic Text element

This is my html code


<a id="youtube" href="#">
<i class="fab fa-youtube-square"></i>
</a>

This is my js code

let lyrics =
[
    {
        lyric: '"lyrics goes here"',
        artist: '- artist',
        link: "https://www.youtube.com/watch?v=ox7RsX1Ee34" 
    },
]

let button = document.getElementById("button")

let lyric = document.getElementById("lyric")

let artist = document.getElementById("artist")

let link = document.getElementById("youtube")

button.addEventListener('click', () => {
    var random = Math.floor(Math.random() * lyrics.length)
    lyric.innerHTML = lyrics[random].lyric;
    artist.innerHTML = lyrics[random].artist;
    link.innerHTML= lyrics[random].link;
})

This is what it looks like currently

When I press the youtube button I want it to take me to the link.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you want to send the user to the url of the youtube video, use window.open:

button.addEventListener('click', () => {
    var random = Math.floor(Math.random() * lyrics.length);
    lyric.innerHTML = lyrics[random].lyric;
    artist.innerHTML = lyrics[random].artist;

    window.open(lyrics[random].link);
}

Alternatively, you could set the href of the link and then click it to go to the page:

button.addEventListener('click', () => {
    var random = Math.floor(Math.random() * lyrics.length);
    lyric.innerHTML = lyrics[random].lyric;
    artist.innerHTML = lyrics[random].artist;

    link.href = lyrics[random].link;
    link.click();
}

and to make it open in a new tab: <a id="youtube" target="_blank">

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda