I have a simple code. I want to click on the button and alert its id. The button is contained in a div. Both button and div have a click()
bound to them.
Problem: If I click the button the id of button is alerted and then id of div is also alerted afterwards. I want to prevent the id of div from being alerted.
Code:
<html>
<body>
<style type="text/CSS">
#mydiv{
border: 1px dashed blue;
width: 90px;
height: 50px;
}
</style>
<div id="myDiv">
<input type="button" id="myButton" value="Click Me"></input>
</div>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="code.js"></script>
</body>
</html>
Code.js:
$('#myDiv').click(function(){
alert($('#myDiv').attr('id'));
});
$('#myButton').click(function(){
alert($('#myButton').attr('id'));
});