Fred J. Fred J. - 8 months ago 97
jQuery Question

jQuery contents is not a function

This jQuery code tries to get all the comments elements in a page, but is returning error when run in the browser console.

TypeError: $(...).contents is not a function

How can I get all the comments nodes in a page? Thankx

$("*").contents().filter(function() {
return this.nodeType == 8;


Ithink $ refers to some other library in your page, so use jQuery instead of $. Also check jQuery library is included before the code in your page.

jQuery("*").contents().filter(function() {
  return this.nodeType == 8;

Also don't forget to wrap the code by document ready handler.