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

225
Views
Javascript: cómo obtener el texto del elemento onclick en una lista desplegable dinámica

El siguiente código siempre muestra la opt 5 en lugar de en la que hice clic.

En HTML:

 <div id = "dropdown_1" class="dropdown"> <button onclick="dropdown_toggle()" class="dropbtn">Dropdown</button> <div id="myDropdown" class="dropdown-content"> </div> </div>

En otro archivo js :

 var select = document.getElementById("myDropdown"); var options = ["opt 1", "opt 2", "opt 3", "opt 4", "opt 5"]; for(var i = 0; i < options.length; i++) { var opt = options[i]; var el = document.createElement("a"); el.textContent = opt; el.value = opt; el.onclick = function(event) { console.log(opt); } select.appendChild(el); }
about 4 years ago · Juan Pablo Isaza
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!