Mohammad Ali Akbari
Mohammad Ali Akbari

Reputation: 10395

each() and multiple events trigger the same function

I want run some code on each select on page load and re-run it by some events on each select separately. currently done with following:

jquery(function(){
  $('#myID select').each(function(){
    alert('SE');
  });

  $('#myID select').bind('keyup keypress blur change',function(){
    alert('SE');
  });
});

Can I merge them into one?

Upvotes: 1

Views: 84

Answers (1)

VisioN
VisioN

Reputation: 145398

You may trigger one of the events on DOM ready:

$(function() {
    $("#myID select").bind("keyup keypress blur change", function() {
        alert("SE");
    }).keyup();  // or .trigger("keyup");
});

Upvotes: 3

Related Questions