Fred J. Fred J. - 1 year ago 236
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;

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download