views:

51

answers:

3

I wonder if there's any SEO difference between using a regular a href-link or making an element clickable by adding javascript onclick?

Basic example of the my two options...

<a href="myUrl">Link</a>

<div onclick="javascript:yUrl">Link</div>
+3  A: 

Since web spiders are (still) Javascript-free, the obvious difference between the two bits of code is, one can be followed by a bot (and anyone else) while the other only works for users with Javascript enabled (so, not Google). For spiders, it should be nothing more than a div, and whatever url you're setting with onclick will not be followed (and therefore, not indexed from that page).

Stomme poes
This! The link will not be followed, and in the eyes of the bots, it's not a link.
Martin
Thank you for your quick answer. Just to sum up, if I want to develop a page that's get indexed by Google I have to use mainly a href-links..
Creole
+1  A: 

Typically, yes. Crawlers by-and-large just care about the mark-up, not the transitional state as would be modified by JS so a JS created link will be invisible to them (which may be a useful thing in it's own right). One reason for this is that JS engines are a layer of considerable complication above what a crawler requires and another is that JS is simply not expected to modify the content, just the behaviour. Anchors are the semantic structure intended for these relationships.

Search owners keep their mechanisms hidden but having worked for one [insignificant one] in the past I can say that anchors with hrefs were basically the only thing our crawlers considered, and anchors with rel were scored highly.

annakata
+2  A: 

Possibly, it's known that Google executes some JavaScript. I don't know why you would want to do this though. If you are trying to stop browsers folowing links, you could try rel="nofollow".

Douglas
This answer is correct as Google will crawl some JavaScript and is capable of understanding why it is used. It does this primarily to stop people who took advantage of the lack of JavaScript crawling to spam users.
EnderMB