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 ;)
If you put # inside the href like <a href="#"></a> then the link will not refresh or reload when clicked.
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!
After you set the specified URL into location, issue window. location. reload(true) . This will force browser to reload the page.
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.
Just add javascript:void(0) in href you will get..
<a href="javascript:void(0)">Link</a>
I think javascript:;
also works.
<a href="javascript:;">Link</a>
Simply don't specify href
attribute:
<a>Link</a>
A link without href
...
pointer
on hoverunderlined
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With