Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
89
rated 0 times [  95] [ 6]  / answers: 1 / hits: 30114  / 10 Years ago, sun, september 21, 2014, 12:00:00

This question may be duplicate of any. But, after lot of try I couldn't find the proper solution for this.



This is my code



@Styles.Render(~/Content/css)
@Scripts.Render(~/bundles/modernizr)
@Scripts.Render(~/bundles/jquery)
@Scripts.Render(~/bundles/bootstrap)
<script>
$(document).ready(function () {
var els = document.querySelectorAll('body > *');
els[els.length - 1].remove(); //getting error here
})
</script>


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



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


When i can run same function in browser console window and it works. but, when i place my code in the page it shows me error like above. I have also tried to call .removeNode(boo) method but, it was also not working. Actually when i try to write ele[].remove() in the code the intellisence doesn't suggest me that function.


More From » jquery

 Answers
6

DOMNodes don't have a remove() method. 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();
});

[#69385] Thursday, September 18, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
charlesmarions

Total Points: 310
Total Questions: 96
Total Answers: 107

Location: Netherlands
Member since Wed, Feb 8, 2023
1 Year ago
;