Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8556695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:24:41+00:00 2026-06-11T15:24:41+00:00

When I try to pass text which spreads throughout a few block elements the

  • 0

When I try to pass text which spreads throughout a few block elements the window.find method dosent work:

HTML:

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
</head>
<body>
  <p>search me</p><b> I could be the answer</b>
</body>
</html>

JavaScript:

window.find("meI could be");

Or:

str = "me";
str+= "\n";
str+="I could be t";

window.find(str);

This happens when the <p> element is present between the search term.

How can I fix that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:24:42+00:00Added an answer on June 11, 2026 at 3:24 pm

    As option:

    function containsStr(str) {
        return document.body.innerText.indexOf(str) > -1;
    }
    

    Just tested it and it’s working same as window.find. Or window.find is working same as this my function.
    Anyway seems it’s depends to element’s style.display property.
    E.g. when I set

    p {
        display: inline;
    }
    

    this call window.find("me I could be")​ returns true for your HTML example.

    I created this example to test mentioned behavior.
    As option you can create a div element in memory, get document.body.innerHTML and set retrieved value to div’s innerHTML, then change style.dysplay to "inline" for elements within this div similar to what I did in my code example, and then perform a search.

    UPDATE #1: jQuery

    I’ve made deeper research and found that usage of jQuery :contains selector is working better than my previous function and than window.find, but may be more expensive (not sure, need to be tested).

    function containsStr$(str) {
        return $('body:contains("'+str+'")').length > 0;
    }
    

    UPDATE #2: pure JavaScript solution

    function _find(str) {
        var div = document.createElement('div');
        div.innerHTML = document.body.innerHTML;
        var elements = div.getElementsByTagName('*');
        for(var i = elements.length; 0 > i--;) {
            elements[i].style.display = 'inline';
        }
        return (div.innerText || div.textContent).indexOf(str) > -1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I try to pass text which spreads throughout a few block elements the
With window.open method I open new site with parameters, which I have to pass
I try to parse an xml file. The text which is in tags is
I have the following code, with which i try to dynamically pass my arguments
I have a helper method that serialises an object, which works until you try
I have a web from that has a few text boxes which are visible
What is the difference between ',' and 'as' in except statements, eg: try: pass
I try to pass variable from jquery to code c# but something is wrong.
I try to pass a structure as a parameter. Global structure: struct ThreadParams {
When I try to pass the results of a Linq query in to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.