I want to remove ‘element’ which is created in javascript from a div x

These are all the definitions I have done

const x =document.getElementById('desc');
let element = document.createElement('h4');

let complTasks = document.getElementById('completed');

This is the code I have written

rmButton.onclick = function () {
  x.removeChild(element)
  element.removeChild(button)
  element.removeChild(rmButton)
  alert(element.innerHTML + " is removed by you")
    rmButton.onclick = function () {
        complTasks.removeChild(element)
     }

I am getting the error failed to execute ‘removeChild’ on ‘Node’: The node to be removed is not a child of this node.at rmButton.onclick