I am attempting to handle multiple concurrent events using jQuery but I am having problems finely managing when the events are fired.
<html>
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
</head>
<body>
<div id="edit" contenteditable="true">Edit some content</div>
<button id="button" type="button">Click the button</button>
<script type="text/javascript">
$(document).ready(function () {
$('#button').click(function (e) {
alert('I have been clicked.');
});
$('#edit').blur(function (e) {
alert('I have been edited.')
});
});
</script>
</body>
</html>
What I wish to achieve is for the content of the DIV to be edited by a user and when the button is clicked, for that event to be raised before the blur event on the DIV. It may be the case that the button is never clicked in which case the blur event may fire on its own. As you can see using the code above, once you edit the content and click the button only the blur event is fired.
Please can someone advise how I may achieve the desired functionality?