Check 08.07 · JavaScript and HTML rendering

Avoid links that rely solely on JS events

Find the cards, buttons, dropdowns and clickable divs that navigate with JavaScript, and replace them with real links without losing the behavior.

Priority
Critical
Difficulty
Intermediate
Estimated time
2 h to 2 days
Free, no account: your progress is saved in this browser.

Ask an AI to check this point on your site

Opens the assistant with a ready-made question: this check, its goal and your site URL.

For Gemini, Copilot or another assistant, copy the question. The link opens the chosen service directly: nothing goes through this site.

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:

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:

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:

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 (opens in a new tab).

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:

<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>
.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.

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

<a href="/produits/chaise-oslo" data-suivi="carte-produit">Oslo chair</a>
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.

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

<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:

<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 (opens in a new tab).

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:

<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:

// Avoid for navigation
<div onClick={() => router.push(`/produits/${produit.slug}`)}>{produit.nom}</div>
// 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

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.

Updated on

Topic checklist (PDF)

And now?

In the “JavaScript and HTML rendering” topic

  1. Inspect the initial HTML
  2. Compare initial HTML and rendered DOM
  3. Test rendering in Search Console
  4. Prefer SSR/SSG for critical content if relevant
  5. Make content accessible without user interaction
  6. Make links available in HTML with href
  7. Avoid links that rely solely on JS events
  8. Check title, description and canonical after rendering
  9. Check rendered structured data
  10. Fix JS and hydration errors
  11. Check content loaded via API
  12. Check dynamic pagination
  13. Check SPA HTTP status codes
  14. Avoid information available only in Canvas
  15. Test which information is accessible without JS