I’m using Jquery in Visual Studio ASP.net. I’m trying to display a message everytime someone clicks on a specific image link (class=”button notice buttonEight” below) on a page. Here’s a snippet of the code from the page:
<li class="levelOne"><a class="button notice buttonEight" href="#">
<img src="<%= Page.ResolveUrl("~/PBS-Intranet/_res/_images/icon_notice.png") %>"/></a></li>
</ul>
<div class="endCap">
</div>
<script type="text/javascript">
$(document).ready(function() {
$("icon_notice").click(function() {
var src = $(this).attr('src');
alert("Hello world!");
});
});
</script>
You need to actually tell jQuery what you’re clicking, the computer has no idea what
$("icon_notice")is. Add the idicon_noticeto your image, then select it with$("#icon_notice")and that code should work great.