How to use JQuery?

Hi guys!
Is there a way to use jquery in case that I need to make some changes on Algolia Search page (instant search) on Zendesk?
I’ve tried but no results with jquery.
Also, there is no console.log errors.

Thanks,
Vlad

1 Like

Hi there!

You mean modifying things on the page after the search has been rendered?
If that’s what you mean, it’s actually fairly easy:

  1. The lib exposes its instances in algoliasearchZendeskHC.instances
  2. You should have called it only once, so you can grab the first instance in the array [0]
  3. Then the associated instantsearch instance is linked through the instantsearch attribute
  4. instantsearch.js exposes the render event to know when the page has been updated, you can plug your jQuery code here.
  5. You need to call search() a new time to produce a new render of the page the first time. It won’t do a new call to the API, same calls on a page without a reload are cached with our JavaScript client.
var search = algoliasearchZendeskHC.instances[0].instantsearch;
search.on('render', function () {
  console.log('The page has been updated');
});
search.helper.search();

Hope this helps!

3 Likes

Very helpful! Thanks @Jerska !