views:

64

answers:

2

Hi, 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.

Thanks

A: 

try jQuery selector

hallie
Will match elements based on the limited set of conditions that can be expressed with selectors. It won't match strings.
David Dorward
+2  A: 

document.innerHTML is undefined

var source = document.getElementsByTagName('html')[0].innerHTML;
var found = source.search("searchString");

N 1.1
this definitely works for a normal string. But, when you have to search something like id="'myId'" , this doesnt seem to work.
kambamsu
kambamsu - please don't use innerHTML to search for HTML. Use the DOM! That's what it's meant for...
J-P
@J-P: Kambansu wants to search everything, including ids, classes, attributes. It can be done using DOM, but that would be complex huh?
N 1.1
-1? please be kind to correct(comment) me :)
N 1.1
@kambamsu, if you're searching for id="myId" then you have to escape the string, or switch the quotes. Html requires the doubles quotes. So your search string would have to look like "id=\"myId\""
David Archer