Simulate the anchor click with jQuery

Posted on Monday September 12, 2011 / by Eric Potvin

Some search engines consider a lot of links on your page as not good for SEO. If you have more than 100 links on your page, it may be considered less useful.

If someone asked you where to buy new clothes, would you recommend 100 clothing stores to them? Of course not. That wouldn't be helpful for them. You would want to provide the best stores you know.

One hundred links in a web page is just a suggestion. The more you have, the less of a chance that someone will be interested in them.

An anchor tag might not be the best option to slide down a menu or remove duplicate links for SEO. Instead, using a span tag might be a better solution.

Slide down menu:

$(document).ready(function() {
  $('#triggerMenu').click(function() {
    $('#menu').slideToggle('slow', function() {
      // Animation complete.
    });
  });
});
<span id="triggerMenu">open menu</span>
<div id="menu">
  <ul>
    <li><a href="/" title="My Page">My Page</a></li>
    <li><a href="/articles/" title="My Articles">My Articles</a></li>
  </ul>
</div>

Remove duplicate links

$(document).ready(function() {
  $('#mainLinkSpan').click(function(){
    window.location = $('#mainLink').attr('href');
  });
});
a, span.link {
  font: normal 14px Tahoma;
  text-decoration: underline;
  color: blue;
  cursor: pointer;
}
<h1>title</h1>
// some content
<a id="mainLink" href="/mypage/" title="my page">my page</a>
// some content
<span id="mainLinkSpan" class="link">my page</span>

This way, search bots won't try to reference the "open menu" link.