Filtering Elements in jQuery
Using the filter method, you can leave only those elements in the set that satisfy a certain selector.
Let's look at the HTML code:
<p>text</p>
<p>text</p>
<p class="www">text</p>
<p class="www">text</p>
Let's find all paragraphs, prepend them with the text '!' using prepend, then get only the paragraphs with the class www from the found ones using the filter method and prepend them with the text '?' using append:
$('p').prepend('!').filter('.www').append('?');
Find all li in the set, then use filter to select all li with class www and append '!' to them.