August 3, 2010
Using div background image as link using jQuery
Question by Jean
I have put a logo as the background image in a div
<div id="logo" style="background-image:url(images/logo.jpg); position:absolute; top:20px; left:18%; width:275px; height:100px; cursor:pointer;"></div>
I want to use this as div as a link using jquery
//jQuery code
$('#logo').bind('click',function() {
window.location = "index.php"
});
Neither does the cursor:pointer
show up nor does the link work, any ideas.
Thanks
Jean
Answer by Sarfraz
Make sure that you wrap your code in ready handler like this:
$(function(){
$('#logo').bind('click',function() {
window.location = "index.php"
});
});