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

20th Aug 2020, 5:01 AM
Cam UOR
Cam UOR - avatar
4 Respostas
+ 6
From your code: function show() { document.getElementById("mess").innerHTML = {name} } Should be: function show(obj) { document.getElementById("mess").innerHTML = obj.name }
20th Aug 2020, 6:30 AM
Kurt Sicht
Kurt Sicht - avatar
20th Aug 2020, 6:08 AM
Kurt Sicht
Kurt Sicht - avatar
0
https://code.sololearn.com/WOVI52QYpBNi/?ref=app
20th Aug 2020, 6:01 AM
Cam UOR
Cam UOR - avatar
0
I visualise it above because the sentence was not explained very well.
20th Aug 2020, 6:02 AM
Cam UOR
Cam UOR - avatar