The “onclick” attribute does what it sounds like: it’s activated when a user clicks it. However, Googlebot will follow the href reference, while users experience the onclick.
A hyperlink that has both the href and onclick attribute can be deleted.
Table of Contents
Avoid Formats That Aren’t Href
Google's guidelines on crawlable links states that "Google can follow links only if they are an <a> tag with an href attribute. Links that use other formats won't be followed by Google's crawlers. Google cannot follow <a> links without an href tag or other tags that perform as links because of script events."
Here are a few examples that Google offers for links that can and cannot be followed:
Can follow:
<a href="https://example.com">
<a href="/relative/path/file">
Cannot Follow:
<a routerLink="some/path">
<span href="https://example.com">
<a onclick="goto('https://example.com')">
As such, when your hyperlinks contain both a href and an onclick attribute, the crawlers will only follow the href reference while users may be experiencing the onclick only. The onclick is JavaScript powered, so Google may not be able to follow those links.
This could cause issues if the page referenced in the href is not the page you intend to be indexed.
How to Solve This Issue
You can choose to delete the hyperlink that has both href and onclick.
Deleting a hyperlink requires you to implement changes directly to your site. This change may be able to be made through the CMS.
If not, the hyperlink can be removed from your site’s code. If you don’t have the necessary edit access to make such changes, your dev team should be able to assist you.
How to Delete Hyperlinks at Scale
Links can be deleted at scale, across thousands of pages in a matter of minutes with SEO execution platform ClarityAutomate. Here’s the simple 3-step process.
- Select what you’d like to optimize: Links
To make optimizations to your site’s links, that’s what you first select in ClarityAutomate.
- Choose how you'd like to optimize it: Delete
This solution calls for deleting the links with both the href and onclick.
- XPath location: XPath of broken hyperlink on the page
As a final step, enter the XPath of the hyperlink to be removed. Then, push your changes live!
Before and After
That’s all it takes. ClarityAutomate lets you implement critical site fixes in a matter of minutes.
In this case, we’ve deleted the hyperlink that included the onclick:
Looking for other hyperlink issues?