.remove is not a function
21,912
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();
});
Related videos on Youtube

Comments
-
Shell 4 months
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 writeele[].remove()
in the code the intellisence doesn't suggest me that function. -
isherwood about 8 yearsAh, yes. Must use a jQuery object.
-
Shell about 8 yearsyeah its working fine.. Now error is gone and everything is running ok. I really would like to accept ur answer. but, SO says me wait for 8 mins. :P
-
JLRishe almost 5 years@kevinwaite It was deleted because you posted your question as an answer. If you have a question about your own code, you can click the Ask a question button at the top of the page.
-
JLRishe almost 5 years@kevinwaite I can't answer your question because it has been closed. Having been a member of this site for more than six years, you should know how to properly ask a question. There is a link underneath your question to a page that explains how to do so, but in case you can't find it, here you go: stackoverflow.com/help/mcve
-
JLRishe almost 5 years@kevinwaite "the problem I ran into was the there was no way for that image to be added here" There's your first problem. You should be putting code in your question. Not pictures of code. "the powers-to-be DELETED if from there" You posted a question as an answer. Of course it was deleted. Why are you still complaining about that? "I created a new question to hold this image and point to it from here, and the powers-to-be gave me two down votes and put that question on hold" Yes, because it did not meet the standards for a valid question on this site and still does not meet them.
-
JLRishe almost 5 years@kevinwaite It seems that you still haven't read the MVCE page that has been provided to you multiple times, or if you did, you didn't pay any attention to what it said. If you can't be bothered to provide the necessary detail required for questions on this site, then don't expect an answer. "To be honest this is makes me extremely less likely to use this site." That would be nobody's fault but your own.
-
JLRishe almost 5 years@kevinwaite While you're at it read this link too. A big problem with your question is that you haven't explained anything about your code, what anything in it refers to, and what you are attempting to do. How is anyone supposed to know what
data.aaData
orQuery#
are if you haven't told us? -
kevinwaite almost 5 yearsYou should had told me to get the code and paste here.
-
kevinwaite almost 5 yearsLet us continue this discussion in chat.
-
kevinwaite almost 5 yearsHow would I apply this solution to my scenario where the 'dataTable' is constructed as a parameter, the focus line being data.aaData[i] = data.aaData[i].remove['Query#']; which fails because '.remove()' is not a function.
-
JLRishe almost 5 years@kevinwaite "there is something called context -- this question is in context of removing a column from a 'dataTable'" What kind of dataTable? dataTable could mean any one of hundreds of different things so without further detail,that's as good as nothing. " it is also obvious that 'Query#' is the column I want to remove." Yeah, but I have no idea what kind of dataTable it is, so without that, I have no idea how columns are stored in it. "Look at the this question. it is solving the same problem" The code in this question doesn't remotely resemble the code you're working with and I'm ...
-
JLRishe almost 5 yearspretty sure your issue is almost completely unrelated to what the OP here was asking about. "You should had told me to get the code and paste here." No, I absolutely do not want you to paste a whole load of code in the comments under my answer here. "how?" If you've read the page about MVCEs and still don't understand how your question fails to measure up to what's described, I don't know what to tell ya bub. Based on the information you've given so far, I still have no idea how to answer your question, and even if I did, I wouldn't answer it here in the comments.
-
JLRishe almost 5 yearsAsk a question properly and there's a very good chance that somebody will answer.