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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:55:55+00:00 2026-06-15T12:55:55+00:00

I have written a simple javascript searcher for a page and am running into

  • 0

I have written a simple javascript searcher for a page and am running into some problems with mismatches/false matches as well as potentially poor css class matching.

http://jsfiddle.net/C4q7T/

If I click on the first example ‘code’ (which filters down to one element) then on the ‘styling’ link, the ‘code’ high-lighting remains. Needless to say this is undesirable.

I think that the problem will happen in the filtering part of the code but it all looks quite good to me. Especially since I am grabbing the text of the title rather than the HTML of it and then adding in a new span.

function filter(searchTerm) {
    var searchPattern = new RegExp('(' + searchTerm + ')', 'ig');  // The brackets add a capture group

    entries.fadeOut(150, function () {
        noResults.hide();

        $('header', this).each(function () {
            $(this).parent().hide();

            // Clear results of previous search
            $('li', this).removeClass('searchMatchTag');

            // Check the title
            $('h1', this).each(function () {
                var textToCheck = $('a', this).text();
                if (textToCheck.match(searchPattern)) {
                    textToCheck = textToCheck.replace(searchPattern, '<span class="searchMatchTitle">$1</span>');  //capture group ($1) used so that the replacement matches the case and you don't get weird capitolisations
                    $('a', this).html(textToCheck);
                    $(this).closest('.workshopentry').show();
                }
            });

            // Check the tags
            $('li', this).each(function () {
                if ($(this).text().match(searchPattern)) {
                    $(this).addClass('searchMatchTag');
                    $(this).closest('.workshopentry').show();
                }
            });
        });

        if ($('.workshopentry[style*="block"]').length === 0) {
            noResults.show();
        }

        entries.fadeIn(150);
    });
}

Some other combinations make this happen but some other s do not, making it very hard for me to track down the cause for this particular problem.

  • 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-15T12:55:56+00:00Added an answer on June 15, 2026 at 12:55 pm

    Turn out I was missing a check to remove the previous matching tags.

    var textToCheck = $('a', this).text();
    if (textToCheck.match(searchPattern)) {
        //capture group ($1) used so that the replacement matches the case and you don't get weird capitolisations
        textToCheck = textToCheck.replace(searchPattern, '<span class="searchMatchTitle">$1</span>');
        $('a', this).html(textToCheck);
        $(this).closest('.workshopentry').show();
    } else {
        $('a', this).html(textToCheck);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a simple web Application which is running(on Tomcat Server) fine on
I have written some JavaScript code that will read from the Google Maps API
I have written a simple javascript code to remove whitespace from a text box.
I have written a quite simple javascript method, which should send an ajax request
I have written a very simple Chrome extension. It consists of this background page:
I am in the process of learning backbone.js and have written some very simple
I have written a simple Javascript function (curteousy of codecall.net ) that creates a
I have written some JavaScript code. It adds new function to NodeList type in
I have a problem with a very simple piece of code written in Javascript,
I have written simple code to get content from xml file to php. $xml

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.