# No method to use to jump back & forth between search results

**URL:** <https://pdfjs.community/t/no-method-to-use-to-jump-back-forth-between-search-results/2400>\
**Category:** Technical Support\
**Tags:** pdfjs-express\
**Created:** [February 27, 2023, 9:48am UTC](https://pdfjs.community/t/no-method-to-use-to-jump-back-forth-between-search-results/2400 "2023-02-27T09:48:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ons.othmen](https://avatars.discourse-cdn.com/v4/letter/o/6de8d8/32.png) [@ons.othmen](https://pdfjs.community/u/ons.othmen)\
**Post date:** [February 27, 2023, 9:48am UTC](https://pdfjs.community/t/no-method-to-use-to-jump-back-forth-between-search-results/2400/1 "2023-02-27T09:48:53Z")

</div>

**Which product are you using?**  
pdfjs-express

**PDF.js Express Version**  
8.4.0

**Detailed description of issue**  
We are trying to create an event listener on the search panel, on keydown we will be binding [↑], [↓] to navigate search results, but there is no where documented how to navigate to the previous and next search result.

**Expected behaviour**  
Expected to have methods that navigate to the previous and next search result, just like the arrows in the search panel.

 ![Screenshot 2023-02-27 at 10.48.00](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/0/00eb0e87838f041843db6e04f0bf8c15ce3dbd70.png)

**Does your issue happen with every document, or just one?**  
all

## **Link to document**

## **Code snippet**

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [February 27, 2023, 7:57pm UTC](https://pdfjs.community/t/no-method-to-use-to-jump-back-forth-between-search-results/2400/2 "2023-02-27T19:57:11Z")

</div>

Hi there,

Thanks for reaching out to pdf.js express forums,

You would be calling the ‘searchText’ method again to get to the next result:

> **[Basic searching | Documentation](https://pdfjs.express/documentation/search/basic-search.8#searching-a-document-one-by-one)**

Additionally, these are the hotkeys we have available:  
[https://pdfjs.express/api/UI.Hotkeys.html](https://pdfjs.express/api/UI.Hotkeys.html)

Best regards,  
Kevin Kim

---

<div class="post-metadata">

**Author:** ![ons.othmen](https://avatars.discourse-cdn.com/v4/letter/o/6de8d8/32.png) [@ons.othmen](https://pdfjs.community/u/ons.othmen)\
**Post date:** [February 28, 2023, 10:17am UTC](https://pdfjs.community/t/no-method-to-use-to-jump-back-forth-between-search-results/2400/3 "2023-02-28T10:17:43Z")

</div>

Thank you Kim for your response, but it is a bit not clear, could you provide a piece of code that I could use/inject in mine?

Much appreciated,  
Ons.

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [February 28, 2023, 5:16pm UTC](https://pdfjs.community/t/no-method-to-use-to-jump-back-forth-between-search-results/2400/4 "2023-02-28T17:16:23Z")

</div>

Hey there,

You could remove the ‘arrow down’ event key via ‘off’ method:

`instance.UI.hotkeys.off(instance.UI.hotkeys.Keys.DOWN);`

Then add a new event for that hotkey with ‘on’:

```javascript
instance.UI.hotkeys.on('DOWN', e => {
    const searchValue = 'your_search_text'

    instance.UI.searchText(searchValue, {
        // ...options // see the API reference for options
    })
});

```

Best regards,  
Kevin Kim

---

<div class="post-metadata">

**Author:** ![ons.othmen](https://avatars.discourse-cdn.com/v4/letter/o/6de8d8/32.png) [@ons.othmen](https://pdfjs.community/u/ons.othmen)\
**Post date:** [March 1, 2023, 10:13am UTC](https://pdfjs.community/t/no-method-to-use-to-jump-back-forth-between-search-results/2400/5 "2023-03-01T10:13:31Z")

</div>

This is only for the arrow down I assume, what about arrow up? (going to the previous search result)

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [March 1, 2023, 5:04pm UTC](https://pdfjs.community/t/no-method-to-use-to-jump-back-forth-between-search-results/2400/6 "2023-03-01T17:04:47Z")

</div>

Hi there,

It looks like we do not have a specific method to go back to previous search result.

We do however have the API textSearchInit:  
[https://pdfjs.express/api/Core.DocumentViewer.html#textSearchInit](https://pdfjs.express/api/Core.DocumentViewer.html#textSearchInit)  
From there, you can add an option for the searchMode:  
[https://pdfjs.express/api/Core.Search.html](https://pdfjs.express/api/Core.Search.html)

The other method that could work is to create an event to click the UI button:

```javascript
var element = document.querySelector('[aria-label="Previous result"]');
element.click()

```

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/2/2a9103d1f8e4f0109bcb7044b749306f40f4f828.png)

Best regards,  
Kevin Kim
