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.
A TypeError: "x" is not a function occurs when a function is called on an object that does not contain the called function. When calling a built-in function that expects a callback function argument, which does not exist. When the called function is within a scope that is not accessible.
remove() The Element. remove() method removes the element from the DOM.
DOMNode
s 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();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With