0

I was participating in a special shopping event in a site (www.mi.com/in/) and I tried to view the HTML source through the browser in curious. I was looking for a code of button and I found the href is defined to javascript: void(0) and I thought they might have hidden the link somehow( maybe with some special web language) so nobody can direct go to the link. So I ask you, is there any present web technology available to hide a link in HTML code when parsing? screenshot - take a look:enter image description here

  • 1
    http://stackoverflow.com/questions/7452341/what-does-void-0-mean – ShufflerShark Oct 17 '16 at 09:05
  • Like @RobbyCornelissen has pointed out, it is indeed javascript. And from a development point of view it's a best practice, rather than that of hiding links. This is because it creates a separation of view & your business logic. – Keith Oct 17 '16 at 09:07
  • @Keith — Best practise would be to use a real link and prevent the default behaviour (as a fallback) or a button (because it isn't linking anywhere). `href="javascript:void(0)"` is terrible. – Quentin Oct 17 '16 at 09:20
  • @Quentin Your correct, if SEO is important. But I was thinking from an App POV. But saying that if SEO is important, I think the new micro data tagging etc is nicer. – Keith Oct 17 '16 at 09:31
  • @Keith — SEO is beside the point. It's better for humans. JavaScript fails for all sorts of reasons. Different UI components have different affordances. – Quentin Oct 17 '16 at 09:32
  • @Quentin Not sure what you mean, but if my javascript fails in App mode, I'd rather it fails end off. Anyway, lets move on, were maybe a cross purposes here. – Keith Oct 17 '16 at 09:39

1 Answers1

3

Yes Javascript void(0) means this link will not perform functionality of href. You can use HTML5 data- attributes and then use jquery to perform javascript operations on clicking of that link

$(document).ready(function(){
$('[data-action=clickElement]').click(function(){alert('the element is clicked')});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="javascript:void(0);" data-action='clickElement'> 
  link
</a>
Asim Khan
  • 572
  • 6
  • 34