How to find a certain string in the current document?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fernando

    #1

    How to find a certain string in the current document?

    Hi,

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

    Thanks!
  • dhtml

    #2
    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

    • Dr J R Stockton

      #3
      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

      Working...