When I click the message button, it won’t call alert() ..can anybody check the code please?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Homepage</title>
<script type="text/javascript" src="lib/jquery/jquery-1.4.2.js"></script>
<script type="text/javascript" src="lib/jquery/jquery-ui-1.8.10.custom.min.js"></script>
<script type="text/javascript" src="lib/jquery/jquery.dmDropDownMenu.js"></script>
<script type="text/javascript" src="lib/jquery/watermark.js"></script>
<link rel="stylesheet" type="text/css" href="/jquery-ui-1.8.10.custom.css" />
<link rel="stylesheet" type="text/css" href="/stylez.css" />
<script type="text/javascript" /> $(document).ready( function(){ $('#buttons button').click(function(){ switch( $('buttons').id){ case "mail": alert(1); break; } }); }); </script>
</head>
<body>
<table width="1000" border="0" cellpadding="0" cellspacing="0">
<tr>
<td id="columnA">
<div id="buttons">
<button id="mail" class="menubutton">Message</button><br/>
</div>
</td>
</tr>
</table>
</body>
</html>
If you want to check which button has been clicked and you are going to have multiple buttons, you can use
$(this)inside the.click(), it will reference THE object which was clicked. So change the switch to:The full lot:
See a working demo here