Say a web page has a string such as \"I am a simple string\" that I want to find. How would I go about this using JQuery?
Normally jQuery selectors do not search within the "text nodes" in the DOM. However if you use the .contents() function, text nodes will be included, then you can use the nodeType property to filter only the text nodes, and the nodeValue property to search the text string.
$('*', 'body') .andSelf() .contents() .filter(function(){ return this.nodeType === 3; }) .filter(function(){ // Only match when contains 'simple string' anywhere in the text return this.nodeValue.indexOf('simple string') != -1; }) .each(function(){ // Do something with this.nodeValue });