+ 2

What is the best method to remove an element in HTML using javascript?

30th Jan 2019, 6:27 AM
Sandakan Nipunajith
Sandakan Nipunajith - avatar
4 Réponses
+ 2
With jQuery you could just use the remove method on the element. eg: $("ELEMENT").remove(); And as Calvin said if you wanted to remove it's parent then, $("ELEMENT").parent().remove();
30th Jan 2019, 8:57 AM
Seniru
Seniru - avatar
+ 4
refer its parent and then remove element itself. E.g. if(element.parentNode) element.parentNode.removeChild(element);
30th Jan 2019, 6:41 AM
Calviղ
Calviղ - avatar
+ 2
The best way it's element.remove() If you wanna remove the parent Element.parent().remove() But this only works with Jquery
30th Jan 2019, 2:47 PM
Ferry
Ferry - avatar
- 2
element
30th Jan 2019, 6:35 AM
Yrral Jarrah
Yrral Jarrah - avatar