Hey guys at the moment i am trying to make a for loop to create some buttons in my html dont think about the alt.on function cause it is based on altv(GTA 5 Multiplayer Servers). I am getting from somewhere else the data of applist and with that data i am trying to make the buttons in a for loop the thing is that i want this buttons to be childs of a div that already exists with a classname in the html and i need to definde a onClick = "blafunction();" for the each button.
alt.on('data-from-server', (applist) => {
let app = JSON.parse(applist);
for (i = 0; i < app.length; i++) {
var button = document.createElement("button");
button.id = app.id;
document.body.appendChild(button);
};
});
idvalue for multiple elements on a page. Other than that, it looks like you're doing it right. Since you're already writing JavaScript, I'd suggest usingbutton.addEventListener("click", blafunction)-- or better yet, just add one click listener to the document and decide how it should behave based on which element was clicked. (When you defineblafunction, you would just sayfunction blafunction(event){ const thingThatWasClicked = event.target; ... }).