When you build your button here:
<button id='btnid' onclick='editPost(this.innerHTML)'>" + btnid + "</button>"
You already have access to the button ID via the
btnid
variable. So, why not just inject that directly into the
onclick
method like so:
<button id='btnid' onclick='editPost(" + btnid + ")'>" + btnid + "</button>"
Then you can assign whatever value you want to the button's inner HTML. An alternative way is to use
data-*
attributes which are a good way to store data on elements:
<button id="btnid" onclick="editPost(this)" data-id='" + btnid + "'>" + btnid + "</button>"
// Javascript
function editPost(button) {
const id = button.getAttribute('data-id');
...
}