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

108
Visualizações
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 à 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