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 181105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:42:11+00:00 2026-05-11T14:42:11+00:00

how can i search an html page for a word fast? and how can

  • 0

how can i search an html page for a word fast? and how can i get the html tag that the word is in? (so i can work with the entire tag)

  • 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. 2026-05-11T14:42:11+00:00Added an answer on May 11, 2026 at 2:42 pm

    To find the element that word exists in, you’d have to traverse the entire tree looking in just the text nodes, applying the same test as above. Once you find the word in a text node, return the parent of that node.

    var word = 'foo',     queue = [document.body],     curr ; while (curr = queue.pop()) {     if (!curr.textContent.match(word)) continue;     for (var i = 0; i < curr.childNodes.length; ++i) {         switch (curr.childNodes[i].nodeType) {             case Node.TEXT_NODE : // 3                 if (curr.childNodes[i].textContent.match(word)) {                     console.log('Found!');                     console.log(curr);                     // you might want to end your search here.                 }                 break;             case Node.ELEMENT_NODE : // 1                 queue.push(curr.childNodes[i]);                 break;         }     } } 

    this works in Firefox, no promises for IE.

    What it does is start with the body element and check to see if the word exists inside that element. If it doesn’t, then that’s it, and the search stops there. If it is in the body element, then it loops through all the immediate children of the body. If it finds a text node, then see if the word is in that text node. If it finds an element, then push that into the queue. Keep on going until you’ve either found the word or there’s no more elements to search.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wanting to allow users to tag items so that they can search
My question is how can I get the HTML of one page and store
How can I search for words in between html tags? Say I have the
This is quite weird but my search function can search for any word except
I have a search page that is used in multiple places with multiple 'themes'
I am wondering how to set the default button in html page, so that
I am really wondering if i can use search for a HTML website. The
My project implements search (from default HTML page) and will redirect to the search
On an html page, can I calculate an invidual character's x,y coordinates and its
Im trying to create a page in which users can search for items on

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.