I'm trying to add delete buttons in javascript which deletes itself on-click yet I don't know how. Here's my code:
<script>
function displayPost(){
var thisDiv = document.getElementById("posts");
var theDate = document.createElement("P");
theDate.classList.add("post-date");
var trash= document.createElement("BUTTON");
trash.classList.add("post-trash");
trash.innerHTML = '<i class="fa fa-window-close" aria-hidden="true"></i>';
thisDiv.appendChild(theDate);
thisDiv.appendChild(trash);
theDate.innerHTML = new Date();
trash.onclick = del(this);
}
function del(x){
var delTrash = document.getElementsByClassName("post-trash");
var delDate = document.getElementsByClassName("post-date");
var index = deltrash.indexof(x);
thisdiv.removeChild(hideTrash[index]);
thisdiv.removeChild(delDate[index]);
}
</script>
Sorry I'm pretty new to Javascript. Any sort of help is appreciated. Thank you