Skip to content

Custom JavaScript events in Bricks

Bricks dispatches custom JavaScript events for several frontend actions. Use these events when your own scripts need to respond to Bricks forms, popups, query filters, AJAX updates, tabs, accordions, or other interactive elements.

Since Bricks 2.5, the Copy to clipboard interaction dispatches these events on the element that owns the interaction:

  • bricks/clipboard/success: The browser confirmed that the text was copied.
  • bricks/clipboard/fail: Clipboard writing failed or the source element could not be found.

event.detail.text contains the copied or attempted text. It is null if the source text could not be read. These events do not bubble, so attach listeners directly to the element that owns the copy interaction.

const copyButton = document.querySelector('#copy-coupon')
copyButton?.addEventListener('bricks/clipboard/success', (event) => {
console.log('Copied:', event.detail.text)
})
copyButton?.addEventListener('bricks/clipboard/fail', (event) => {
console.log('Could not copy:', event.detail.text)
})

Replace #copy-coupon with your copy element’s selector and run this code after that element exists in the DOM. To configure feedback in the builder, use the Copy successful and Copy failed triggers.

// Listen for the 'bricks/tabs/changed' event
document.addEventListener('bricks/tabs/changed', (event) => {
// Extract information from the event detail
const { elementId, activeIndex, activeTitle, activePane } = event.detail;
// Only target elementID lwxvfh
if( elementId !== 'lwxvfh' ) {
return;
}
// Example: Log the details to the console
console.log(`Tabs Changed - Element ID: ${elementId}, Active Index: ${activeIndex}, Active Title: ${activeTitle}, Active Pane: ${activePane}`);
// Your custom logic here
// For example, update the UI based on the tab change
});

Accordion / Accordion (Nestable) element events

Section titled “Accordion / Accordion (Nestable) element events”
  • bricks/accordion/open: Emitted after an accordion item is opened/expanded via click action (@since 1.9.8)
  • bricks/accordion/close: Emitted after an accordion item is closed/collapsed via click action (@since 1.9.8)
// Listen for the 'bricks/accordion/open' event
document.addEventListener('bricks/accordion/open', (event) => {
// Extract information from the event detail
const { elementId, openItem } = event.detail;
// Only target elementID qwe3th
if( elementId !== 'qwe3th' ) {
return;
}
// Example: Log the details to the console
console.log(`Accordion Opened - Element ID: ${elementId}, Open Item ID: ${openItem}`);
// Your custom logic here
// For example, update the UI based on the accordion item being opened
});
// Listen for the 'bricks/accordion/close' event
document.addEventListener('bricks/accordion/close', (event) => {
// Extract information from the event detail
const { elementId, closeItem } = event.detail;
// Only target elementID qwe3th
if( elementId !== 'qwe3th' ) {
return;
}
// Example: Log the details to the console
console.log(`Accordion Closed - Element ID: ${elementId}, Closed Item ID: ${closeItem}`);
// Your custom logic here
// For example, update the UI based on the accordion item being closed
});
  1. bricks/ajax/popup/start
  2. bricks/ajax/popup/end
  3. bricks/ajax/popup/loaded
  4. bricks/popup/open
  1. bricks/ajax/start
  2. bricks/ajax/nodes_added
  3. bricks/ajax/end
  4. bricks/ajax/load_page/completed
  1. bricks/ajax/start
  2. bricks/ajax/nodes_added
  3. bricks/ajax/end
  4. bricks/ajax/pagination/completed
  1. bricks/ajax/start
  2. bricks/ajax/end
  3. bricks/ajax/query_result/completed
  4. bricks/ajax/nodes_added
  5. bricks/ajax/query_result/displayed

For standalone AJAX pagination, bricks/ajax/pagination/completed includes isPopState: true during Back/Forward restoration. Check queryUpdated before acting on replaced results: a standalone completion event can also follow a failed request.

After all standalone query restoration requests for the current history navigation finish successfully, Bricks emits bricks/ajax/pagination/history. Its queryIds array identifies the standalone queries requested for restoration; it can be empty when no standalone query needs refreshing. This event does not wait for queries handled by Query Filters and does not indicate that accumulated Load more or Infinite scroll results were restored. A failed standalone history request falls back to loading the target document.

Use this event for site-specific work after the asynchronous restoration, rather than assuming a popstate listener runs after results have loaded. Bricks does not disable native browser scroll restoration.

document.addEventListener('bricks/ajax/pagination/history', (event) => {
const { queryIds } = event.detail;
if (!queryIds.includes('your-query-id')) return;
// The requested standalone query results have finished restoring.
});

The bricks/filter/submit/start and bricks/filter/submit/end events are specific to the Filter - Submit element. They run only for AJAX filter submissions that refresh the current page results. They are not emitted when the Submit element redirects to another URL.

  1. bricks/filter/submit/start
  2. bricks/ajax/start
  3. bricks/ajax/end
  4. bricks/ajax/query_result/completed
  5. bricks/ajax/nodes_added
  6. bricks/ajax/query_result/displayed
  7. bricks/filter/submit/end

Use these events when your script should react only to a deliberate submit action, not to every query filter AJAX request.

document.addEventListener('bricks/ajax/start', (event) => {
// Get the queryId from the event
const queryId = event.detail.queryId || false;
if (!queryId) {
return;
}
// Your custom logic here
// For example, initiate a loader or update UI to indicate AJAX request start
});
document.addEventListener('bricks/ajax/end', (event) => {
// Get the queryId from the event
const queryId = event.detail.queryId || false;
if (!queryId) {
return;
}
// Your custom logic here
// For example, initiate a loader or update UI to indicate AJAX request end
});
document.addEventListener('bricks/ajax/pagination/completed', (event) => {
const { queryId, queryUpdated, isPopState = false } = event.detail;
if (!queryUpdated) return;
// isPopState identifies standalone Back/Forward restoration.
// Add your query-specific logic here.
});
document.addEventListener('bricks/ajax/load_page/completed', (event) => {
// Extract information from the event detail
const { queryTrailElement, queryId } = event.detail;
// Your custom logic here
// For example, handle the completed AJAX page load for the specific queryId and queryTrailElement
});
document.addEventListener('bricks/ajax/query_result/completed', (event) => {
// Extract information from the event detail
const queryId = event.detail.queryId;
// Your custom logic here
});
document.addEventListener('bricks/ajax/nodes_added', (event) => {
// Extract queryId from the event detail
const queryId = event.detail.queryId;
// Your custom logic here
// For example, initialize scripts that need the new AJAX result nodes to exist first
});
document.addEventListener('bricks/ajax/query_result/displayed', (event) => {
// Extract information from the event detail
const queryId = event.detail.queryId;
// Your custom logic here
});
document.addEventListener('bricks/filter/submit/start', (event) => {
const { queryId, filterId } = event.detail;
// Only react to the Filter - Submit element with Bricks ID xnueeh
if (filterId !== 'xnueeh') {
return;
}
// Your custom logic here
});
document.addEventListener('bricks/filter/submit/end', (event) => {
const { queryId, filterId } = event.detail;
// Only react to the target query with Bricks ID kpmnav
if (queryId !== 'kpmnav') {
return;
}
// Your custom logic here
});
  • bricks/megamenu/repositioned: Emitted after a mega menu submenu is repositioned on the frontend. The event detail contains the menuItem and submenu. (@since 2.0)
document.addEventListener('bricks/megamenu/repositioned', (event) => {
const { menuItem, submenu } = event.detail;
// Your custom logic here
// For example, update third-party scripts inside the repositioned submenu
});