Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

249
Views
Agregar un enlace al elemento de texto idiomático

este es mi codigo html

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

Este es mi codigo js

 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; })

Así es como se ve actualmente

Cuando presiono el botón de youtube quiero que me lleve al enlace.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Si desea enviar al usuario a la URL del video de YouTube, 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); }

Alternativamente, puede configurar el href del enlace y luego hacer clic en él para ir a la página:

 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(); }

y para que se abra en una nueva pestaña: <a id="youtube" target="_blank">

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!