Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

href must not reload

Tags:

html

hyperlink

I am testing the following link:

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

But, as expected, it reloads my current page. How can I prevent it from reloading the page, but maintaining the -a- tag assigned to it?

Thanks ;)

like image 628
gespinha Avatar asked Sep 04 '13 04:09

gespinha


People also ask

How to make href not reload page?

If you put # inside the href like <a href="#"></a> then the link will not refresh or reload when clicked.

What does href =# do?

Definition and Usage The href attribute specifies the URL of the page the link goes to. If the href attribute is not present, the <a> tag will not be a hyperlink. Tip: You can use href="#top" or href="#" to link to the top of the current page!

How do I refresh a page using anchor tag?

After you set the specified URL into location, issue window. location. reload(true) . This will force browser to reload the page.


4 Answers

If you don't want it to behave like a link, then don't use a link tag. Doing so hurt accessibility of a page, and you don't want that. There are other ways of browsing a website than a browser (think about the screen readers), which relies on the semantics of the page elements. Use a span if you simply want to apply a style.

If you still want to use an anchor, you can use this -

<a href="#" onclick="return false;">Link</a>

This will prevent your page reloading.

like image 80
MD Sayem Ahmed Avatar answered Oct 16 '22 18:10

MD Sayem Ahmed


Just add javascript:void(0) in href you will get..

<a href="javascript:void(0)">Link</a>
like image 24
Jagadeesh Avatar answered Oct 16 '22 18:10

Jagadeesh


I think javascript:; also works.

<a href="javascript:;">Link</a>
like image 6
Si7ius Avatar answered Oct 16 '22 19:10

Si7ius


Simply don't specify href attribute:

<a>Link</a>

A link without href...

  • does not reload a page on click
  • does not change cursor to pointer on hover
  • does not change text style to underlined
like image 1
naXa Avatar answered Oct 16 '22 19:10

naXa