A jQuery plugin that facilitates quering the DOM (Document Object Model) based on comment values and psuedo-attribute values.
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example
src
vendor/jquery
LICENSE.md
README.md

README.md

jQuery.fn.comments() For Finding Comments In The DOM

by Ben Nadel (on Google+)

The jQuery.fn.comments() method provides a way to search the Document Object Model (DOM) for the existence of comments. The method can be called with a variety of signatures:

  • .comments() - Get all comments in the given node, using a shallow search.
  • .comments( true ) - Get all the comments in the given node, using a deep search.
  • .comments( value ) - Get all the comments in the given node that exactly match the given value, using a shallow search.
  • .comments( value, true ) - Get all the comments in the given node that exactly match the given value, using a deep search.
  • .comments( name, value ) - Get all the comments in the given node that contain the given pseudo attribute pair, using a shallow search.
  • .comments( name, value, true ) - Get all the comments in the given node that contain the given pseudo attribute pair, using a deep search.

The last two take signatures take a name and a value and then try to locate comments based on the given pseudo attribute. Since comment nodes don't really have attributes, the jQuery plugin will look for constructs that look like normal element attributes. In the following comment, there are 3 attributes:

<!-- id=34 name="Ben" deactivated -->

Behind the scenes, this results in the following attributes:

  • id: "34"
  • name: "Ben"
  • deactivated: ""

Because the comments() method can have multiple signatures, it may get confused if your "value" parameter is a Boolean. When in doubt, pass the "value" in as a String.