Reputation: 14382
I have a textbox for which i have written the blur
event handler and i have another button for which i have the click
event written. i dont want to dispatch the blur
event if it's due a click on the button.
Is there any way of doing this?
Upvotes: 2
Views: 1800
Reputation: 6602
Try this :
function blurr() {
alert('blur')
}
$(function(){
$('textarea').blur(function(){blurr()})
$(':button').click(function(){alert('click')})
$(':button').hover(function(){
$('textarea').unbind('blur');
},function(){
$('textarea').bind('blur',function() {blurr()});
})
})
Eg: jsFiddle
Upvotes: 1
Reputation:
$('yourblurbutton').bind('blur', function() {
yourblurfunction();
});
$('yourclickbutton').bind('click', function() {
//your click code
});
$('yourclickbutton').bind('mouseover', function() {
$('yourblurbutton').unbind('blur');
});
$('yourclickbutton').bind('mouseout', function() {
$('yourblurbutton').bind('blur', function() {
yourblurfunction();
});
});
yourblurfunction() {
// your blur function
}
The mouseover event will be triggered before the blur, so it makes us able to unbind the blur. On mouseout, we simple add the blur again.
Upvotes: 4