I'm searching a way to find text spanning multiple nodes in similar way Firefox does it, eg.
With given HTML:
<p>Lorem ipsum <b>dolor</b> si开发者_运维知识库t amet.</p>
When I search for text "ipsum dolor" by ctrl+f Firefox will selects that text, ie. will create Range object(s).
I know I can easily search for text within text nodes (vide Find text string using jQuery?) but this doesn't work in above example.
This will select all p
elements that contain the text specified as an argument to indexOf
. The text
method gets the contents of all text nodes of an element, so the b
tag in your example will not matter:
$("p").filter(function() {
return $(this).text().indexOf("ipsum dolor") > -1;
});
See it working here.
window.find
is exactly what I'm looking for.
精彩评论