---
title: Scope Custom JavaScript to a Specific Page
url: https://docs.maxio.com/billing/public-pages/settings/scope-custom-javascript-to-a-specific-page
applies_to: Advanced Billing
updated: 2026-11-04
---

# Scope Custom JavaScript to a Specific Page

Use the following snippets to detect which type of hosted page your custom JavaScript is running on, so you can scope specific code to just that page instead of every page.

Add custom JavaScript under **Config > Settings > Public Page Default Settings > Custom JavaScript**.

> These selectors are scoped to Public Signup, Receipt, and Self-Service Pages. `#self-service-page` is also present on the Bank Account Verification page, and `.public-signup-page` is also present on the Bank Account Verification and Pay Invoice pages. Neither of those pages runs your custom JavaScript, so the selectors never fire there.

## Modern layout

Self-service page only. Self-Service Pages run only the **Custom JavaScript - Classic (v1)** field, even when your signup pages use the Modern layout, so put this code in the Classic field.

```js
if ($('#self-service-page').length === 1) {
  // code here
}
```

Public signup page and receipt page only

```js
if ($('.public-signup-page').length !== 0) {
  // code here
}
```

Receipt page only

```js
if ($('.public-signup-page__success').length === 1) {
  // code here
}
```

Public signup page only

```js
if ($('.public-signup-page__signup').length === 1) {
  // code here
}
```

## Classic layout

Public signup page and receipt page only

```js
if ($('#self-service-page').length === 0) {
  // code here
}
```

Receipt page only

```js
if ($('#hosted-payment-history').length !== 0) {
  // code here
}
```

Public signup page and self-service page only

```js
if ($('#hosted-payment-history').length === 0) {
  // code here
}
```

Receipt page and self-service page only

```js
if ($('#total').length === 0) {
  // code here
}
```

Public signup page only

```js
if ($('#total').length === 1) {
  // code here
}
```

## Examples

You may want to change your submit button text to say "Subscribe" on all of your Public Signup Pages. Use the following JavaScript:

```js
$('#subscription_submit').val('Subscribe');
```

This also updates the submit button text on Self-Service Pages, since the same element ID appears on both. Wrap your code in the proper snippet from above to scope it to just the page you want.

Change button text on Public Signup Page only

```js
// MODERN LAYOUT
if ($('.public-signup-page__signup').length === 1) {
  $('#subscription_submit').val('Subscribe');
}

// CLASSIC LAYOUT
if ($('#total').length === 1) {
  $('#subscription_submit').val('Subscribe');
}
```

Change button text on Self-Service Page only

```js
if ($('#self-service-page').length === 1) {
  $('#subscription_submit').val('Update Info');
}
```

The Custom CSS and Custom JavaScript fields look the same whether you're editing the site-wide Public Page Default Settings or an individual Public Signup Page's own settings.

![Public Signup Page settings with the Custom CSS and Custom JavaScript entry fields highlighted](https://docs.maxio.com/content-images/billing/public-pages/settings/scope-custom-javascript-to-a-specific-page/24261434164493_psp2.png)

*Custom CSS and Custom JavaScript fields on an individual Public Signup Page's settings*
