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

  • SEARCH
  • Home
  • 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 9066989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:50:34+00:00 2026-06-16T16:50:34+00:00

I have implemented a text search in html using javascript also I am able

  • 0

I have implemented a text search in html using javascript also I am able to highlight it, now I am looking to navigate within the html document using a next and previous buttons, If anyone can suggest some options and solutions that would be really great. Thanks in advance.

For reference I am using the below code for highlighting the search text.

function MyApp_HighlightAllOccurencesOfStringForElement(element,keyword) {
  if (element) {
    if (element.nodeType == 3) {        // Text node
      while (true) {
        var value = element.nodeValue;  // Search for keyword in text node
        var idx = value.toLowerCase().indexOf(keyword);

        if (idx < 0) break;             // not found, abort

        var span = document.createElement("span");
        var text = document.createTextNode(value.substr(idx,keyword.length));
        span.appendChild(text);
        span.setAttribute("class","MyAppHighlight");
        span.style.backgroundColor="yellow";
        span.style.color="black";
        text = document.createTextNode(value.substr(idx+keyword.length));
        element.deleteData(idx, value.length - idx);
        var next = element.nextSibling;
        element.parentNode.insertBefore(span, next);
        element.parentNode.insertBefore(text, next);
          element.parentNode.insertBefore();
        element = text;
        MyApp_SearchResultCount++;  // update the counter

      }
    } else if (element.nodeType == 1) { // Element node
      if (element.style.display != "none" && element.nodeName.toLowerCase() != 'select') {
        for (var i=element.childNodes.length-1; i>=0; i--) {
          MyApp_HighlightAllOccurencesOfStringForElement(element.childNodes[i],keyword);
        }
      }
    }
  }
}
  • 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-16T16:50:36+00:00Added an answer on June 16, 2026 at 4:50 pm

    Here’s a jsfiddle with the idea:
    (see working at http://jsfiddle.net/TAxdp/)

    function goNext(){
        jump(1);
    }
    function goPrev(){
        jump(-1);
    }
    
    function jump(howHigh){
        prevSelected = currSelected;
        currSelected = currSelected + howHigh;
    
        if (currSelected < 0){
            currSelected = MyApp_SearchResultCount + currSelected;
        }
        if (currSelected >= MyApp_SearchResultCount){
            currSelected = currSelected - MyApp_SearchResultCount;
        }
    
        prevEl = document.getElementsByClassName("MyAppHighlight")[prevSelected];
        if (prevEl){
            prevEl.style.backgroundColor="yellow";
        }
        el = document.getElementsByClassName("MyAppHighlight")[currSelected];
        el.style.backgroundColor="green";
        el.scrollIntoView(true); //thanks techfoobar
    }
    

    p.s. “highlight all” must be clicked before next/previous.

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

Sidebar

Related Questions

In my website I have implemented search feature using full-text search. It works fine
I have implemented Full Text Search on one of Sql Server 2008 Table. Query
I have implemented Full Text Search on one of Sql Server 2008 Table. I
Using the django-haystack and solr as a search engine, I have successfully implemented a
I've implemented full text search for a web site using Lucene.NET (Version 2.0). Indexing
I have implemented the jquery scroll text in my php web site. See my
I have implemented the TTS support for reading the Text Strings in my Application,
I have a form with 3 text fields and 3 checkboxes. I had implemented
I'm using Zend_Search_Lucene for full-text search of records in several different tables in my
I have implemented a simple search functionality for my rails 3 blog application. I

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.