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!
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);
$(window).on('resize',function() {
}).trigger('resize');
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