简体   繁体   中英

How to highlight search results with 2 or more html-elements?

I used mark.js for resolving subject, however, it's not working for cases like

<p><b>3</b> results found</p>

So if I try to search "3 results found" I will have 0 matches. However, browser can handle cases like that with ctrl+F. How can I do it using javascript?

To search across multiple HTML elements you'll have to enable the option separateWordSearch of mark.js – which is enabled by default. Since you haven't posted a code example I assume that you've explicite deactivated it.

Here is an example:

 new Mark(document.querySelector("p")).mark("3 results found"); 
 <script src="https://cdn.jsdelivr.net/mark.js/7.0.0/mark.min.js"></script> <p><b>3</b> results found</p> 

If you need an option to search in multiple HTML elements without this option, you'll have to submit a feature request here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM