I'm looking for a way to search the generated source of a webpage ( document.innerHTML) for a string, in javascript.
I wouldn't want to use window.find() since i might have to look for id's or names too.
Any help would be appreciated开发者_Go百科.
Thanks
document.innerHTML
is undefined
var source = document.getElementsByTagName('html')[0].innerHTML;
var found = source.search("searchString");
You could use an indexOf function to search string
var source = document.getElementsByTagName('html')[0].innerHTML;
var foundIndex = source.indexOf(searchString);
OR using regular expression,
var paragraph = 'The quick brown fox jumped over the lazy dog. It barked. ';
var regex = /quick/g;
var found = paragraph.match(regex);
ECMAScript 6
"hello".startsWith("ello", 1) // true
"hello".endsWith("hell", 4) // true
"hello".includes("ell") // true
"hello".includes("ell", 1) // true
"hello".includes("ell", 2) // false
try jQuery selector
精彩评论