JavaScript Help

Soldato
Joined
26 Aug 2012
Posts
4,428
Location
North West
I have the below function that adds an onclick event to a set of list items with the 'LoadConfigureAppModal' class. Now the function works in that upon click of any of these items with this class that the style changes be visible (loads the modal). The next part is that I want to run a function after the modal is loaded that grabs the value for that particular list items 'data-AppId' attribute and populate the modal with the relevant content.

I've got the following but not sure how to get it working, or if there is a better way.

HTML:
for(var i=0; i<loadConfiureAppModal.length; i++) {
    loadConfiureAppModal[i].onclick = function() {
        configureAppModal.style.display = "block";
        getAppDetails(document.getElementsByClassName("LoadConfigureAppModal")[i].getAttribute('data-AppId'));   
    }
}
 
If you pass the event into the function you can then use event.target to refer back to the element which was clicked on.

for(var i=0; i<loadConfiureAppModal.length; i++) {
loadConfiureAppModal.onclick = function(event) {
configureAppModal.style.display = "block";
getAppDetails(event.target.getAttribute('data-AppId'));
}
}
 
If you pass the event into the function you can then use event.target to refer back to the element which was clicked on.

for(var i=0; i<loadConfiureAppModal.length; i++) {
loadConfiureAppModal.onclick = function(event) {
configureAppModal.style.display = "block";
getAppDetails(event.target.getAttribute('data-AppId'));
}
}
Thank you :)
 
Back
Top Bottom