tags:

views:

75

answers:

3

html-

<div class="hbg">
</div>

some menu items here

jquery for mouser over on menu items-

function imgchange()
    {
        $('.smenu li').mouseover( function(){
        var src = $(this).find('a').attr('alt');
        $('.hbg').css('background-image', 'url(' + src + ')');
        $(this).find('hbg').attr('title', 'my tootip info');
        });     
    }

I am changing the background image of hbg div through jquery on mouse over of menu items(ul li).but i want to bind(href) that div to particular page also so that when user clicks anywhere on div it should redirect to that binded page.as it is redirecting on clickin on li items.
Is there any property in jquery where we can set the whole div as hyperlink?

+5  A: 

Here is how you bind a click handler to the div:

$('div.hbg').click(function(e) {
  alert('The div was clicked!');
});

And you probably also want to style it to look clickable:

div.hbg { cursor: pointer; }
twerq
+1 ... on a sidenote does anyone know why is this still showing up as "unanswered" when there is already a multiple upvoted answer?
kekekela
@kekekela: "Answered" means there was an "accepted" answer by the OP (the green check mark appears)
Neil N
@Neil - In this context, I don't think so. When you click on the unanswered tab, it shows in the upper right the count of "questions with no upvoted answers", and you see most answers disappear off of this page and show only under the questions page once they have an upvote. (sort both lists by recent to see what I mean) This question for instance is no longer showing in the unanswered list even though the answer hasn't been accepted yet. Maybe its just slow to update.
kekekela
@kekekela: Caching... it needs some time to update it.
Felix Kling
@Felix thank-you, sir
kekekela
A: 
$('div.hbg').click(function(){location.href='http://www.google.com'});

You may want to change the mouse cursor so it looks clickable:

$('div.hbg').css('cursor','pointer');
Adam
+1  A: 

try to give the div class a width and height and display: block;

Dr Casper Black
div is already a display: block element
twerq