How to execute JavaScript code in the instantsearch page

On our instant search page, the search block is rendered with JavaScript.
Most of it is re-rendered every time a query is made.
Depending on what you want to change in the DOM, you’ll need either to use:

  • init, which is called once before the initial render
  • render, which is called at every render

The best way to see how it’s used is to look at our powered by logo code. It’s called both at init and render times.

    // Logo & clear{
      init: function (opts) {
        if (!instant.poweredBy) {
        $('.ais-clear-input-icon').on('click', function () {
      render: function (opts) {
        if (!opts.state.query) {
          if (instant.poweredBy) {
        } else {

For render, an alternative to that is to use instantsearch.js's render event, like so:'render', function () {
      // Do something

Thanks @p.michael.dy for the question.

Answered in topic post :white_check_mark: