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

98
Views
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
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!