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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:10:38+00:00 2026-05-19T22:10:38+00:00

I am using jQuery and creating now search. And i want to change all

  • 0

I am using jQuery and creating now search. And i want to change all words that match of search.

For example:

i type in textbox “hello world”, Script get all words “hello” and “world” on page and replace it on “<b class="search_word">hello</b>” and “<b class="search_word">word</b>“.

Is it possible?

PS.

Search in div but div contains many other html elements.

now i am using this:

if ($("#search_input").val() != "") {
    var words = $("#search_input").val().split(/\s/g)
    for (var i = 0; i < words.length; i++) {
        var new_reg = new RegExp(words[i], 'gi');
        var replaced = $(".content_area").html().replace(new_reg, "<b class='searched_word'>"+words[i]+"</b>")
        $(".content_area").html(replaced);
    }
}

it works but tags…

if i search something like: “b class is the best class in School” it destroy page structure

  • 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-05-19T22:10:38+00:00Added an answer on May 19, 2026 at 10:10 pm

    Ahh ok, I understand, “onpage” search… hm….

    this is a copy from How do I select text nodes with jQuery?

    var getTextNodesIn = (function() {
        function textNodeFilter() {
            return this.nodeType == 3;
        }
    
        return function(el) {
            var $el = $(el);
            return $el
                .contents()
                .filter(textNodeFilter)
                .add(
                    $el
                       .find("*")
                       .contents()
                       .filter(textNodeFilter)
                );
        };
    })();
    

    you can now use

    getTextNodesIn("body").each(function() {
     var txt = $(this).text();
     $(this).text(txt.replace(new RegExp(myWord,"g"), "<b>" + myWord + "</b>"));
    });
    

    Loop now through all of them and aply my filter previously written.

    There where you found your word, you must select the whole text, and replace the found word with found Word

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

Sidebar

Related Questions

Using jQuery I'm creating a basic 'tooltip' animation so that the tooltip will appear
I'm creating a page that loads content from other pages using jQuery like this:
I am creating a custom simple dropdown using jQuery that hides/shows a element based
For rendering SVG I'm using jQuery SVG plugin. And, now I want to add
Using Jquery TableSorter, I am creating a custom parser to sort elapsed time <td>
Using jQuery in IE8, I'm creating a div with a class (ex. <div class=className></div>
Am creating a script using JQuery on an ASP.NET page. Have a JSON string
I am creating an XML string using JQuery. I would like to open a
I am creating an app using jQuery Mobile and PhoneGap. I delegate a button
I'm creating a CMS using jQuery and AJAX. When I click, my Add Campaign

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.