I have a div that contains an image :
<div class="HD">
<img class="image1"src="img/myimage.png">
</div>
the CSS applied to it is :
.HD img {
position:absolute;
top:570px;
left:1120px;
width:30px;
height:90px;
cursor:pointer
}
I want to apply a click function to the image inside the div. However, when I give an image id or class and use that to create the function the javascript does not fire. When the div does not have an image and I use the class the javascript works as expected. Below is the Javascript function :
$(".HD").click(function () {
if($('.UpperDiv').attr('data-visible') == "hidden") {
$('.UpperDiv').attr('data-visible', 'visible');
$('.UpperDiv').animate({
opacity:1
// top:'250px'
});
} else {
$('.UpperDiv').attr('data-visible','hidden');
$('.UpperDiv').animate({
opacity:0
// top:'250px'
});
}
});
What could be the reason ? What is wrong with my code ?
How can I fire the javascript, when the user clicks on a div that contains an image?
For reference, this is the website I am trying to make, and the original working version.