Dejan.S
Dejan.S

Reputation: 19138

.trigger('blur') on collection of inputs?

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

Answers (1)

Silver Light
Silver Light

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

Related Questions