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)