How to find a certain string in the current document?

D

dhtml

Fernando said:
Hi,

How can I find if the current document contains a certain substring?

You could get the textContent/innerText of body and check to see if the
string exists.

var body = document.body,
text = "textContent" in body ? body.textContent : body.innerText;

var searchString = "test";

var hasText = text.indexOf(searchString) != -1;

Garrett
 
D

Dr J R Stockton

In comp.lang.javascript message <d859522e-cf17-4f57-8228-486accbccad6@e3
9g2000hsf.googlegroups.com>, Wed, 17 Sep 2008 10:52:07, Fernando
How can I find if the current document contains a certain substring?
Maybe with document.body.innerHTML.match(/String/g)
or OK = /String/.test(document.body.innerHTML)

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top