0
How to access attributes of class members in a single function?
I want to create a function that when selected takes information from the button that was used, while using the same function as every other button ( Example: If Person 1 name= Harry and Person 2 name= George, Then the function access the Person and number to get the name and will log either Harry or George based on whether button A or B is pressed without needing two seperate buttons) I don't know if that makes sense, but please help as I would like to create dozens of these buttons using one function and do not want to have to make a dozen seperate buttons for the same function. I have Person as the class, 1 and 2 as people in the class and name as an attribute of the class
4 Respostas
+ 6
From your code:
function show() {
document.getElementById("mess").innerHTML = {name} }
Should be:
function show(obj) {
document.getElementById("mess").innerHTML = obj.name }
+ 4
Have a look at this:
https://code.sololearn.com/Wx95PfoUQE7z/?ref=app
0
https://code.sololearn.com/WOVI52QYpBNi/?ref=app
0
I visualise it above because the sentence was not explained very well.