Hi guys, i have made a simple convertor using HTML+CSS+JS which takes an input and converts it into different dimensions and displays it in a dynamically created <p> element inside a div. When i enter new input, it shows the conversion below previous <p> element. How to erase previous conversion when entering a new input? I have tried to google it but i couldn't understand much.
#How to reset or clear child element in a div?
3 messages · Page 1 of 1 (latest)
This method should do the trick:
function clearChildren(element) {
while(element.lastChild) {
element.removeChild(element.lastChild);
}
}```
removeChild()
https://www.w3schools.com/jsref/met_node_removechild.asp
If You want to remove all children, You can use innerHTML = ''