im trying to trigger('blur');
on a collection of inputs but i does not seem to get this right.
example is avaible here http://jsfiddle.net/VUUme/1/
im getting the collection and i got the blur method done but im not sure about the trigger part tho.
var $inputs = $('#form').find('input');
alert('load');
$inputs.each(function(){
$(this).trigger('blur');
});
//i tried this to but with no success
//$inputs.trigger('blur');
alert('after the blur');
$inputs.blur(function(){
var $this = $(this);
if ($this.val() == ''){
alert('it works');
}
});
trigger( "blur" ) in the third. The blur event is sent to an element when it loses focus. Originally, this event was only applicable to form elements, such as <input> . In recent browsers, the domain of the event has been extended to include all element types.
Input.blur( ) — remove keyboard focus from a form element.
blur() method removes keyboard focus from the current element.
Preventing the blur If you want to prevent the blur event from being fired, you have to do so when you are inside the mousedown event, you can do so by invoking the method preventDefault() on the event. Click the checkbox, focus input & then click the button, the textfield never loses focus now.
Put trigger()
after you define $inputs.blur()
:
alert('after the blur');
$inputs.blur(function(){
var $this = $(this);
if ($this.val() == ''){
alert('it works');
}
});
$inputs.trigger('blur');
Updated fiddle: http://jsfiddle.net/VUUme/3/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With