As the title says, I have exactly the same code needs to run in both functions. Is there a way to put them together and run as one function please? Thanks!
Asked
Active
Viewed 9,777 times
2 Answers
25
Yes. Simply define a function with the common code and pass that as the argument to the two methods.
var callback = function () {
// This is the common code
};
$(document).ready(callback);
$(window).resize(callback);

JaredPar
- 733,204
- 149
- 1,241
- 1,454
-
3Why do you use a var instead of just naming the function? – davidcondrey Jul 20 '14 at 23:15