Or Betzalel
Or Betzalel

Reputation: 2597

Refresh Page On Div Click

I have a div and inside that div I have my site logo etc...

I want that when the user clicks the site logo (my div) it will redirect him to the homepage.

How do I do it? (div onlick??)

Upvotes: 1

Views: 2717

Answers (6)

Spliffster
Spliffster

Reputation: 7219

<div onclick="window.location.href = '/';">...</div>

replace '/' with your URL or URI.

Upvotes: 7

Chris
Chris

Reputation: 27619

Will an anchor tag work for this (I don't know what your HTML is like, etc.). It will be more semantically correct and will not require javascript. I don't think there are any browsers that object to DIV elements inside A elements.

http://jsfiddle.net/4s87y/

<a href="http://www.google.com">
    <div style="height: 100px; background-color: #ffcccc;">
        This is a test. Woohoo!
    </div>
</a>

Upvotes: 2

Shekhar_Pro
Shekhar_Pro

Reputation: 18430

If you want it for OnClick then use it like this

<div OnClick="window.location=http://example.com">Your Content and Logo</div>

Upvotes: 0

TheVillageIdiot
TheVillageIdiot

Reputation: 40517

one way is to use: onclick="function(){ location.href = 'http://www.yoursite.com'; }"

another one is to put the div with site logo inside an anchor tag like <a href="yoursite.com"><div>sitelogo</div></a>

Upvotes: 1

Erik
Erik

Reputation: 630

<img src="logo" onclick="window.location('myHomePage');">

<div onclick="window.location('myHomePage');">stuff inside the div</div>

you can also change the window.location for a window.refresh(); if you want to refresh the page.

Upvotes: 2

jocull
jocull

Reputation: 21135

<div onclick="window.location='http://www.google.com';" style="cursor:pointer;">Content...</div>

Replace http://www.google.com with the relative path to your site's root. The style tag just switches the cursor to a pointer so user's know it's clickable.

Upvotes: 3

Related Questions