I have a JSON file and i want to get its id by clicking on name
[
{ "" : 1
, "id" : 201610501
, "name" : "MainMenu"
, "parent": null
}
,
{ "" : 2
, "id" : "201610501*"
, "name" : "(*) Repeat"
, "parent": 201610501
}
]
and im fetching it like this
fetch('https://uccx116p.ef.com:8445/3rdpartygadget/files/JSON_files/Retailer_UC_1.json')
.then(res => res.json())
.then(data => {
console.log(data)
document.querySelector("#app").innerHTML = data.map(user => {
return `<li id="list" onclick="openMessageBox(this)" ><a href="#"> ${user.name}</a>
</li>
`
})
})
.catch(() => console.log('cant'))
}
openMessageBox = function(el){
var name =el.textContent
console.log(name);
Right now on clicking the name im getting its name but I want to change it into its id how can I do that?