October 22, 2024
Chicago 12, Melborne City, USA
jQuery

Trigger event when searched term is found jQuery


When a user presses Ctrl + F (PC) or Cmd + F (Mac) in a browser, a search field pops up allowing you to search for a word. If it finds a word, it highlights it on the page. So in the example below, if you search for "pink" it will pull two results, and you can navigate to each one.

So here’s my question: when it finds a word and highlights it, can you detect that event and trigger an action? For example, highlight the found word in red and make it bold?

      <h2>Section with a Paragraph</h2>
      <p>Here is some text content</p>
      <h2>Section with a Div and Mixed Content</h2>
      <div>
        <h3>Heading</h3>
        <p>Here is some content with text and a link.</p>
        <p><a href="https://duckduckgo.com" target="_blank">Duck Duck Go</a></p>
        <p>Pink</p>
      </div>
      <h2>Section with a List</h2>
      <ul>
        <li>Dogs</li>
        <li>Cats</li>
      </ul>
      <h2>Section with an article</h2>
      <article>
        <p>This is an <code>&lt;article&gt;</code> element</p>
        <p>Pink</p>
      </article>



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video