# Avoid links that rely solely on JS events

- Check 08.07 · JavaScript and HTML rendering · Critical
- Source: https://checklist-seo-geo.com/en/javascript-html-rendering/avoid-links-that-rely-solely-js-events
- Find the cards, buttons, dropdowns and clickable divs that navigate with JavaScript, and replace them with real links without losing the behavior.
- Updated on 2026-11-25
- Licence: CC BY 4.0. Credit “Checklist SEO & GEO” with a link to https://checklist-seo-geo.com/en/javascript-html-rendering/avoid-links-that-rely-solely-js-events.
- Plugin checklist-seo-geo: 1.3.1 · https://github.com/maximegaul/checklist-seo-geo

## In short

An “event-based” link is an element that changes page only when a script reacts to the click: a product card with `onclick`, a button that calls `router.push()`, an `<a href="#">` whose real destination is in the JavaScript, a dropdown that redirects on change. To a crawler, it is not a link. This check consists of finding them and replacing them with real `<a href>` links, while keeping animations, analytics tracking and fast navigation. Expected result: every navigation to an indexable page goes through a link that can be opened in a new tab.

## Why it matters

Crawlers do not click. They read the HTML, or the rendered DOM in Google's case, and look for `<a>` tags with an `href` attribute. Google's documentation lists, among the links it cannot reliably parse, an `<a onclick="goto('...')">` without `href`, a `<span href="...">` and an `href="javascript:..."`. An `onclick` handler is never run to discover a destination: the target page is not discovered through that path and receives no internal linking signal.

Generative engine crawlers are even stricter, since they do not run JavaScript according to published observations: only the real links in the initial HTML exist for them.

The problem is not only technical. A fake link does not open in a new tab, does not show its address in the status bar on hover, cannot be copied, and is not announced as a link by screen readers. AI agents that browse on the user's behalf also rely on the nature of elements: a link that presents itself as a link is easier to follow.

## What it improves

- **Page discovery**: product pages, articles and category pages linked through cards or buttons become crawlable.
- **Internal linking**: links pass on their signal and their anchor text.
- **Generative engines and AI agents**: their crawlers can follow the navigation. Indirect effect, with no guarantee of being cited.
- **Accessibility and usability**: middle-click, opening in a new tab, keyboard navigation, correct announcement by screen readers.
- **Rankings**: indirect effect, through discovery and internal linking.

## How to check

**1. The right-click test.** Right-click a product card, a “View product” button, a menu item, a page number. If the context menu does not offer “Open link in new tab”, it is not a link.

**2. In the Chrome console**, list the elements that are not links but react to clicks and look like links. `getEventListeners()` is a function available only in the developer tools console:

```js
console.table([...document.querySelectorAll('body *')]
  .filter((el) => !el.closest('a[href], button, input, select, textarea, label, summary'))
  .filter((el) => getComputedStyle(el).cursor === 'pointer')
  .filter((el) => getEventListeners(el).click || el.hasAttribute('onclick'))
  .map((el) => ({ balise: el.tagName, classe: el.className, texte: el.textContent.trim().slice(0, 60) })));
```

Then the fake links:

```js
console.table([...document.querySelectorAll('a:not([href]), a[href="#"], a[href^="javascript:"]')]
  .map((el) => ({ href: el.getAttribute('href'), texte: el.textContent.trim().slice(0, 60) })));
```

A handler delegated at the document level (common with frameworks) does not show up on the element itself: the right-click test remains the most reliable.

**3. In the project's source code**, search for programmatic navigation:

```bash
grep -rn -E "href=\"(#|javascript:)|window\.location(\.href)? *=|location\.assign\(|window\.open\(|router\.push\(|navigateTo\(|wixLocation\.to\(" \
  --include=*.{js,jsx,ts,tsx,vue,svelte,php,liquid,html} .
```

Not every result is a mistake: a redirect after a form submission is legitimate. Only those used to navigate to an indexable page count.

**4. Lighthouse**, SEO category: the “Links are crawlable” audit (`crawlable-anchors`) flags `href` values that are not crawlable.

## How to implement

### Before you start

One rule settles every case: **anything that leads to another page is an `<a href>` link; anything that triggers an action on the page is a `<button>`**. See [Distinguish action buttons from navigation links](https://checklist-seo-geo.com/en/semantic-html-accessibility/distinguish-action-buttons-from-navigation-links).

| Pattern to replace | Replacement |
| --- | --- |
| `<div class="carte" onclick="location.href='/produits/oslo'">` | link in the card title, extended to the whole card with CSS |
| `<button onclick="location.href='/contact'">Contact us</button>` | `<a href="/contact" class="bouton">Contact us</a>` |
| `<a href="#" onclick="ouvrir(12)">` | `<a href="/produits/12">`, script as an enhancement |
| `<a href="javascript:void(0)" data-url="/chaises">` | `<a href="/chaises">` |
| `<select onchange="location = this.value">` | list of links, or a `GET` form with a submit button |
| `<tr onclick="...">` in a table | link in the first cell of the row |
| `window.open('/fiche.pdf')` | `<a href="/fiche.pdf" target="_blank" rel="noopener">` |
| Pagination buttons `onclick="page(2)"` | `<a href="?page=2">` |

### Fully clickable card

The link is placed on the title, and a pseudo-element extends it to the whole card. The anchor text remains the product name:

```html
<article class="carte">
  <img src="/images/oslo.webp" alt="" width="400" height="300">
  <h3><a href="/produits/chaise-oslo">Oslo chair</a></h3>
  <p>Solid oak, woven seat.</p>
  <p class="prix">€189</p>
</article>
```

```css
.carte {
  position: relative;
}

.carte a::after {
  content: "";
  position: absolute;
  inset: 0;
}

.carte a:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 4px;
}
```

If the card contains other interactive elements (an “add to cart” button), give them `position: relative; z-index: 1;` so that they remain clickable above the link.

### Link with tracking or JavaScript behavior

Keep the `href` and add the behavior on top, without blocking navigation:

```html
<a href="/produits/chaise-oslo" data-suivi="carte-produit">Oslo chair</a>
```

```js
document.addEventListener('click', (event) => {
  const lien = event.target.closest('a[data-suivi]');

  if (!lien) {
    return;
  }

  navigator.sendBeacon('/stats', JSON.stringify({ cible: lien.dataset.suivi, url: lien.href }));
});
```

With Google Tag Manager, use a “Click – Just Links” trigger rather than navigation coded in an `onclick`.

### Navigation dropdown

A list of links, possibly collapsed in a `<details>` element, remains crawlable:

```html
<details class="choix-ville">
  <summary>Choose a branch</summary>
  <ul>
    <li><a href="/agences/lyon">Lyon</a></li>
    <li><a href="/agences/nantes">Nantes</a></li>
  </ul>
</details>
```

For a filter that has to remain a `<select>`, use a form that works without a script, then add automatic submission with JavaScript:

```html
<form action="/chaises" method="get">
  <label for="tri">Sort by</label>
  <select id="tri" name="tri">
    <option value="prix">Price</option>
    <option value="nouveautes">New arrivals</option>
  </select>
  <button type="submit">Apply</button>
</form>
```

Filtered pages you want ranked must also receive direct links: see [Control filters and facets](https://checklist-seo-geo.com/en/architecture-navigation/control-filters-facets).

### WordPress

Versions: WordPress 6.4 and later.

- **Page builders**: in the settings of each button, card or icon box, fill in the link (URL) field rather than a custom action or JavaScript code.
- **Blocks**: the “Buttons” block produces `<a href>` links when a link is filled in. Check that no button is left without a link and driven by a script.
- **Theme**: search for `onclick` and `location.href` in the child theme files (`grep -rn "onclick" wp-content/themes/mon-theme-enfant/`).

### Shopify

Versions: Online Store 2.0 themes, Shopify admin, November 2026.

In collection sections and product cards, the title or the image must be `<a href="{{ product.url }}">` links. If a theme makes the card clickable through JavaScript, replace that behavior with the fully clickable card pattern:

```liquid
<article class="carte">
  {{ product.featured_image | image_url: width: 400 | image_tag: alt: '' }}
  <h3><a href="{{ product.url }}">{{ product.title }}</a></h3>
  <p class="prix">{{ product.price | money }}</p>
</article>
```

Variant and currency selectors are actions: they can remain lists or buttons, since they do not lead to a page to be discovered.

### Laravel

Versions: Laravel 11 to 13, Livewire 3 and 4, Inertia 2 and 3.

- **Blade**: replace `onclick="window.location='...'"` with `<a href="{{ route('...') }}">` links styled as buttons.
- **Livewire**: a method called by `wire:click` that ends with `$this->redirect(...)` is not a link. For navigation, use `<a href="..." wire:navigate>`; keep `wire:click` for actions (add to cart, submit).
- **Inertia**: use `<Link href="...">`, which produces an `<a>`. Keep `router.visit()` for redirects after an action. The `Link` component accepts an option that renders it as a button: do not use it for navigation to an indexable page.

### Next.js

Versions: Next.js 15 and 16 (App Router and Pages Router).

`router.push()` in a click handler creates no link:

```tsx
// Avoid for navigation
<div onClick={() => router.push(`/produits/${produit.slug}`)}>{produit.nom}</div>
```

```tsx
// Use instead
import Link from 'next/link';

<Link href={`/produits/${produit.slug}`}>{produit.nom}</Link>
```

`Link` keeps client-side navigation and prefetching. To add tracking, put an `onClick` on the `Link` without calling `event.preventDefault()`.

### Nuxt

Versions: Nuxt 3 and 4.

Replace `@click="navigateTo('/chaises')"` on a `<div>` or a `<button>` with `<NuxtLink to="/chaises">`. `navigateTo()` remains suitable for redirects in a middleware or after a form submission.

### React, Vue and Angular

- **React Router**: `<Link to>` rather than `useNavigate()` in an `onClick`.
- **Vue Router**: `<RouterLink to>` rather than `router.push()` in a `@click`.
- **Angular**: `routerLink` on an `<a>`, which receives an `href`, rather than `this.router.navigate()` in a `(click)` or `routerLink` on a `<button>`.

## Common mistakes

- **Adding `href="#"` to make it a “link”**: the crawler sees a link to the page itself, and the destination stays hidden in the script.
- **Calling `preventDefault()` on every click** to handle navigation yourself: the `href` remains, but middle-clicks and opening in a new tab break. Let the framework's router handle it.
- **Wrapping the whole card in an `<a>` with other links inside**: nested links are invalid HTML. Use the extended pseudo-element.
- **Turning every action button into a link**: “Add to cart” or “Show filter” are actions; they stay `<button>` elements.
- **Fixing the rendered DOM but not the initial HTML**: a real link added only after rendering remains invisible to AI crawlers.
- **Forgetting the anchor text**: a card whose link contains only an image without `alt` produces an empty anchor.

## Frequently asked questions

### Does Google follow onclick links?

No, not reliably. Google crawls links in the form of an a tag with an href attribute; an element that navigates only through an onclick handler, with no href, is one of the cases its documentation advises against. Google does not run click handlers to discover destinations. Add a real href; the handler can stay for tracking or animations.

### How do I make a whole card clickable without JavaScript?

Put an a href link on the card title, then extend its clickable area to the whole card with CSS: the card gets position: relative and the link's ::after pseudo-element gets position: absolute with inset: 0. The anchor text remains the title, the link opens in a new tab and crawlers follow it like any other link.

### Can a button be used to navigate to another page?

No, a button is for triggering an action on the page, such as adding to the cart or opening a panel. To lead to another page, use an a link with an href, styled as a button if the design requires it. Crawlers do not follow buttons, and screen readers announce a button as an action, not as navigation.

### Does router.push stop Google from finding my pages?

Yes, if router.push in a click handler is the only path to a page, Google does not discover it through that link, because it does not click. Use the framework's link component, such as Link in Next.js, NuxtLink or RouterLink: it produces a real a href while keeping fast client-side navigation. Keep router.push for redirects after an action.

## Resources

- [Google Search Central: Make your links crawlable](https://developers.google.com/search/docs/crawling-indexing/links-crawlable)
- [MDN: the a element](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/a)
- [MDN: the button element](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/button)
- [Chrome for Developers: Console Utilities API reference, including getEventListeners](https://developer.chrome.com/docs/devtools/console/utilities)

Next steps: [Make links available in HTML with href](https://checklist-seo-geo.com/en/javascript-html-rendering/make-links-available-html-href), [Distinguish action buttons from navigation links](https://checklist-seo-geo.com/en/semantic-html-accessibility/distinguish-action-buttons-from-navigation-links) and [Test keyboard navigation](https://checklist-seo-geo.com/en/semantic-html-accessibility/test-keyboard-navigation).
