Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

100
Vistas
how to get data from forEach click from loop into another named function

I am trying to get the dataset of a clicked link from within a forEach loop. I am a bit stumped as to how to get that value into another function.

   this.ajaxBtn = document.querySelectorAll('*[ajax-btn]')
this.ajaxBtns = [].slice.call(this.ajaxBtn)

this.ajaxBtns.forEach((item) => {
  item.addEventListener('click', function () {
    let url = item.dataset.link
    console.log(url)
  })
})

function loadDoc() {
  var xhttp = new XMLHttpRequest()
  xhttp.onreadystatechange = function () {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById('results').innerHTML = this.responseText
    } else
      document.getElementById('results').innerHTML =
        '<div class="loader">' +
        '<img src="/eigg/img/ajax-loader.gif" alt="Smiley face" style="width: 50px;height: auto;background-repeat: no-repeat;"></div>'
  }

  xhttp.open('POST', 'content-store/detail/1720/savings-by-design', true)
  xhttp.send()
}

MicroModal.init({
  onShow: (modal) => loadDoc(),
  // [1]
  openTrigger: modalData, // [3]
  closeTrigger: modalClose, // [4]
  openClass: 'is-open', // [5]
  disableScroll: true, // [6]
  disableFocus: false, // [7]
  awaitOpenAnimation: true, // [8]
  awaitCloseAnimation: true, // [9]
  debugMode: false, // [10]
})

so I am trying to get let url = item.dataset.link into the loadDoc() function where the hard coded link appears at the moment xhttp.open('POST', 'content-store/detail/1720/savings-by-design', true)

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda