I was recently working with jQuery and Image slideshow (for which I used Awkward Showcase plugin). I needed to click on the image but my click function was not working which I found very strange. So, finally I arrived at the following solution on “How to respond to user click on a div with image in it”.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery-latest.js"></script> | |
<script type="text/javascript"> | |
$("divClass").live("click", function () { | |
<!-- | |
your definition --> | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="divClass"> | |
<img src="image1.png" alt="gallery" width="110" height="90" /> | |
</div> | |
</body> | |
</html> |
On finding more about it, I found that the problem was that awkward slider was dynamically removing and adding the content to my page. From jQuery API Docs:
live() method provides a means to attach delegated event handlers to the document element of a page, which simplifies the use of event handlers when content is dynamically added to a page.