Overview
The Text Children Plugin is a simple little jQuery plugin to return textual content from selected elements. Unlike jQuery's built-in.text()
method, the textChildren plugin does not recurse through the selected elements' descendants. Quick Start Guide
The Text Children Plugin returns a concatenated string by default, as.text()
does, but can include an optional delimiter, such as a comma or a space, between text nodes. It can also return an array if you prefer that. Each text node's string is trimmed by default, but this feature can be turned off if desired.Add HTML markup to your page and note the elements from which you want to extract textual content. For example, your document may have an unordered list (<ul>) like the following:
<ul id="testlist">
<li>Although <strong>she claimed that</strong> someone <em>stopped by
for a visit, </em><span class="highlight">she swore
that he never</span> slept here
</li>
<li><strong>The rains came down</strong> for forty years
</li>
<li><em>James said</em> he <em>never</em> felt <span class="highlight">that he was</span>
better <strong>at chess</strong> than his son.
</li>
</ul>
Include the jQuery core file and the Text Children plugin in the
<head>
of your document. After these scripts are referenced, you can reference a custom script file to return the desired text nodes (preferred) or enter the script directly in the <head>
(shown below).