How can I fire the onclick event first before the onblur event if I'm currently focused at the textbox in jQuery?
Expected Output: Fire the button click event first before the blur event in the texbox. Alerts "mybtn onclick alert"
Demo: http://jsfiddle.net/Zk8Fg/
Code:
<input type="text" name="fname" id="fname" value="" /><br />
<input type="button" name="mybtn" id="mybtn" value="Click Me" />
<script language="javascript">
$(document).ready(function() {
myFunc();
});
function myFunc() {
$('#fname').focus().blur(function() {
alert('fname onblur alert');
});
$('#mybtn').click(function() {
alert('mybtn onclick alert');
});
}
</script>
Thanks :)
$.focus().blur()
? – Sampson