If you need to insert an HTML element like one <div> or any other element before an existing element in the HTML Document you have to :

1. Get the element by ID :

var table = document.getElementById("clientsTable");

2. Create the HTML element

var div = document.createElement('DIV');
div.innerHTML = '<div> <h1> title </h1> </div>'

3. Insert the element

Here we will use insertBefore function to insert the created Div before the
recovered Table.


If you want to delete an HTML element using JavaScript, try this simple tuto : how to delete a HTML element By Id ?


  1. Pingback: Solution for: (JavaScript / TypeScript) how to delete a HTML element By Id ?

  2. Pingback: (SOLVED) Button Onclick , Alert Input Text Value [HTML + JavaScript]

Laisser un commentaire