Login or Sign Up
Logging in...
Remember me
Log in
Or
Sign Up
Forgot password or user name?
Log in with
Search in titles only
Search in Javascript only
Search
Advanced Search
Forums
BYTES
Product Launch
Updates
Developer Toolkit
Member List
Calendar
Today's Posts
Home
Forum
Topic
Javascript
How to find a certain string in the current document?
How to find a certain string in the current document?
Collapse
This topic is closed.
X
X
Collapse
Posts
Latest Activity
Photos
Page
of
1
Filter
Time
All Time
Today
Last Week
Last Month
Show
All
Discussions only
Photos only
Videos only
Links only
Polls only
Events only
Filtered by:
Clear All
new posts
Previous
template
Next
Fernando
#1
How to find a certain string in the current document?
Sep 17 '08, 05:55 PM
Hi,
How can I find if the current document contains a certain substring?
Thanks!
dhtml
#2
Sep 18 '08, 05:55 AM
Re: How to find a certain string in the current document?
Fernando wrote:
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 = "textConten t" in body ? body.textConten t : body.innerText;
var searchString = "test";
var hasText = text.indexOf(se archString) != -1;
Garrett
Thanks!
Comment
Post
Cancel
Dr J R Stockton
#3
Sep 18 '08, 05:25 PM
Re: How to find a certain string in the current document?
In comp.lang.javas cript message <d859522e-cf17-4f57-8228-486accbccad6@e3
9g2000hsf.googl egroups.com>, Wed, 17 Sep 2008 10:52:07, Fernando
<django@easyjob .netposted:
>
>How can I find if the current document contains a certain substring?
>
Maybe with document.body.i nnerHTML.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.
--
(c) John Stockton, nr London UK. ?@merlyn.demon. co.uk IE7 FF2 Op9 Sf3
news:comp.lang. javascript FAQ <URL:http://www.jibbering.c om/faq/index.html>.
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Comment
Post
Cancel
Previous
template
Next
Working...
OK
OK
Cancel
👍
👎
☕
Comment