How to Fire a jQuery Function When the Page is Loaded and Resized


When building responsive websites you often want to run a script when the page loads. But when you resize the window the layout breaks. You can use the on method to run your code if the page loads or has been resized.

// run on page load and when the window is resized
$(window).on("load resize",function(e){
    console.log("adjust layout");
    $('.page-header').matchHeight(".target");
});

Source



Written by: Jake Lett
I share digital marketing tips and HubSpot tutorials to help marketers and business owners grow their business.

Topic:

Related posts

Tags: ,

Want to Get Email Updates of New Articles?

Join My Email Newsletter