.remove is not a function

This question can be a duplicate of anyone. But after many tries, I couldn't find a suitable solution for this.

This is my code

    $(document).ready(function () {
        var els = document.querySelectorAll('body > *');
        els[els.length - 1].remove(); //getting error here            


I don't know why my application is showing an error in the browser console like

TypeError: els[els.length - 1].remove() is not a function


When I can run the same function in the browser console window and it works. but when i post my code on the page it shows me an error as above. I also tried calling the method .removeNode(boo)

, but it also didn't work. Actually, when I try to write ele[].remove()

in code, intellisence doesn't offer me this feature.


source to share

1 answer


don't have a method remove()

. Use this:

$(document).ready(function () {
    var els = document.querySelectorAll('body > *');
    $(els[els.length - 1]).remove(); 


or even better, this:

$(document).ready(function () {
    $('body > *').last().remove();




All Articles