Emphasize Expandable Sections based on Search Term

I have been working on developing an HTML page for my company that will showcase a list of contacts in an "experts list". Currently, the list is structured using collapsible DIVs nested within each other.

Additionally, the HTML page features a search functionality that allows users to search through the list. Below is the current HTML outline I have...

<div>
    <input type="text" class="live-search-box" placeholder="Search Here" />
    </div>

<div >
    <div role="main" class="ui-content">
        <div data-role="collapsible" data-collapsed="true" data-theme="a" data-content-theme="a">
            <h3>Category</h3>
            <p>Definition</p>
            <div data-role="collapsible" data-theme="a" data-content-theme="a">
                <h3>Sub-category</h3>
                <div data-role="collapsible" data-theme="a" data-content-theme="a">
                    <h3>Location</h3>
                    <p>Point of Contact</p>
                </div><!-- /section 1A -->
            </div><!-- /section 1 -->
        </div>

        <div data-role="collapsible" data-collapsed="true" data-theme="a" data-content-theme="a">
            <h3>Category2</h3>
            <p>Definition2</p>
            <div data-role="collapsible" data-theme="a" data-content-theme="a">
                <h3>Sub-Category</h3>
                <div data-role="collapsible" data-theme="a" data-content-theme="a">
                    <h3>Location</h3>
                    <p>Point of Contact2</p>
                </div>
            </div>
        </div>


    </div>
</div>

One thing I am working on is implementing a Highlight Feature that will highlight the keywords entered in the live-search-box. This will make it easier for users to locate the relevant keyword within the HTML page.

Here is the jsfiddle for the working example I am trying to implement the Highlight feature: https://jsfiddle.net/dgaz8n5k/21/

I have tried using the jQuery highlighter from here, but it interferes with my search feature, which is not desirable.

Any assistance in this matter would be greatly appreciated! Thank you!

Answer №1

Kindly review this JSFiddle.

Whenever a keyup event occurs, ensure the highlighted word is updated.

// Clear previous highlight
$(this).removeHighlight();
// Apply new highlight
$(this).find('h3').highlight(searchTerm);
$(this).find('p').highlight(searchTerm);

The filter method should enclose searchTerm in "" to ensure it is treated as a single parameter without spaces.

'[data-search-term *= "' + searchTerm + '"]'
//                        ^                     ^

Also, remember to include

.highlight { background-color: yellow }
in the css file.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to customize the background color of select2 boxes separately for each option?

I recently implemented the select2 plugin and now I'm looking to add a new class within the .select2-results .select2-highlighted class in order to change the background color. Does anyone have any suggestions on how to achieve this? ...

Unusual symbols in HTML code

While working on a website project that utilizes a web font running on Apache, I encountered an issue specifically on Google Chrome for Android. The text displayed weird characters between existing characters, and initially I thought it was related to enco ...

Problem with loading image from local path in Angular 7

I'm having trouble loading images from a local path in my project. The images are not rendering, but they do load from the internet. Can someone please help me figure out how to load images from a local path? I have already created a folder for the im ...

Spinner displayed upon task completion

Currently, I am developing a project using Spring Boot. I would like to display a spinner on my page to indicate that a task involving heavy calculations is in progress. Even though the page may take up to 5 minutes to load, my spinner only appears for t ...

Button group malfunctions on smaller screens

After integrating a button group into my new website, I noticed that the first two buttons stop functioning properly on smaller screens. Surprisingly, if I remove the text-center div, all buttons cease to work entirely. Despite attempting various solution ...

Struggling to implement dynamic templates in an Angular directive

In the process of developing a small angular application that consists of 3 modes - QA, Production, and Sandbox. In the QA mode, there are multiple buttons for users to select values which then populate "myModel". The other two modes, Production and Sandbo ...

Combining two arrays in JavaScript and saving the result as an XLS file

I have a question that I couldn't find an answer to. I need to merge two arrays and export them to an Excel file using only JavaScript/jQuery. Let's say we have two arrays: Array 1 : ["Item 1", "Item 2"] Array 2 : ["Item 3", "Item 4"] When the ...

`Send data to a C# controller function by utilizing <button> and jquery`

My bootstrap modal contains multiple buttons for downloading files in different formats. I can successfully trigger the controller method by setting the onclick function like this: onclick="location.href='@Url.Action("DownloadAsJPG", "Home")'" ...

The website experiences a sudden crash shortly after launching, displaying the error message "EADDRINUSE" for port 80

PROBLEM I have a react-based website running on a node-express server. My backend server is working fine on port 3000, but the website on port 80 keeps crashing. When I use pm2 to start my website (https://www.edvicer.com) with the command pm2 start serv ...

Create a customized menu with jQuery that disappears when hovered over

Check out this menu I've created: http://jsbin.com/useqa4/3 The hover effect seems to be working fine, but I'm looking to hide the div #submenuSolutions when the user's cursor is not on the "Solution" item or the submenu. Is there a way to ...

What are the best strategies for handling complex task operations in Node.js Express.js?

How can I effectively manage lengthy task functions in Node.js Express.js to prevent timeout errors? Currently, my application includes a time-consuming function that does not require an immediate response but still needs to execute its tasks. How can I en ...

The hyperlink tag within the overlay div is unresponsive

I'm facing an issue with my overlay div (rb-overlay) that pops up when users click on a page option. The overlay takes up the entire page and includes a close button in the top right corner. However, I've noticed that the link at the end of the t ...

Utilizing regular expressions to search through a .md file in JavaScript/TS and returning null

I am currently using fs in JavaScript to read through a changelog.MD file. Here is the code snippet: const readFile = async (fileName: string) => { return promisify(fs.readFile)(filePath, 'utf8'); } Now I am reading my .md file with this fu ...

The art of rotating PDF files and various image formats

Looking for a way to rotate PDF and image files displayed on an HTML page using jQuery. I attempted: adding a CSS class - without success. Here is an example code snippet: .rotate90 { webkit-transform: rotate(90deg); moz-transform: rotate(90de ...

Unable to display SVG icon in Highcharts rendering

Is there a way to add a specific symbol in SVG format to a graph using Highcharts? Highcharts.SVGRenderer.prototype.symbols.download = function (x, y, w, h) { var path = [ "M19 5v14H5V5h14m1.1-2H3.9c-.5 0-.9.4-.9.9v16.2c0 .4.4.9.9.9h16.2c.4 0 ...

Utilizing the Bootstrap grid system to seamlessly display images

I have been attempting to design a column that is divided into two nested columns, each containing images that should fill the entire height and width of their respective columns. However, I am facing an issue where the images are extending beyond the boun ...

Having trouble getting jQuery click event to work with Express for loading a Handlebars page

My jQuery on click function is not working properly in conjunction with Express to route to a handlebars page and display the passed information. I have attempted different solutions such as changing the HTTP method from GET to POST, not using handlebars ...

Having trouble incorporating a function into a specific context menu item within a w2ui grid

I've been struggling with w2ui and grids, trying to extract the id of the specific context menu item that is clicked. My goal is to assign different functions to each menu item based on its id, but I seem to be stuck in figuring out the right approach ...

The functionality of jQuery click events seems to be disabled on the webpage, however, it is working perfectly fine on jsFiddle

After thoroughly checking the js tags and ensuring everything is properly closed, it's frustrating when the JavaScript suddenly stops working. The code functions perfectly in JSFiddle, leading me to believe that the issue may lie with something I&apos ...

Tips for utilizing div as a dropdown menu

I have a challenge with the following code and I am looking to make it function like a dropdown one by one For example: ABCD ABCD 1234 ABCD 1234 abcd <ul class="first"> <li class="first-a"><a href="https://someurl">ABCD&l ...