Reputation: 19138
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');
}
});
Upvotes: 11
Views: 25425
Reputation: 45922
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/
Upvotes: 23