user12828597
user12828597

Reputation:

How do I refresh a page when clicking on a href? | HTML, CSS

What do I have:

HTML, CSS, JS

What do I need:

Reload a page when clicking on <a href>.

What do I know:

I can reload a page using window.location.reload(). To use it in HTML code, I have to put it into <script> tags.

What don't I know:

How to execute this script code when clicking on <a href>.

My code:

<ul>
    ....
    <a href="#" class="currentpage"><li>About us</li></a>
</ul>



What have I tried:

Nothing yet. I have no idea how to link the <script> with <a href>.

Upvotes: 0

Views: 4771

Answers (2)

Kamal Kant
Kamal Kant

Reputation: 1130

You can simply do as below:

<a href="javascript:window.location.reload();"><li>Refresh Page</li></a>

Upvotes: 1

ロバート
ロバート

Reputation: 113

If you want to reload the current page you can use this code:

<a href="#" onclick="myFunction()" class="currentpage"><li>About us</li></a>

<script>
function myFunction() {
  window.location.reload();
}
</script>

It will execute the given function after you click on the link.

Upvotes: 1

Related Questions