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

Browse My Free Website Guides

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


Related resources

  • HubSpot CMS vs WordPress: Feature Comparison and Review
  • 25+ Questions to Ask Before Redesigning Your Business Website
  • 5 Things A Business Should Consider Before a Website Redesign
  • How to Get a Responsive Website for Your Manufacturing Company
  • What Is a Good WordPress Alternative for Businesses?
  • Tags: ,

    Want to Get Email Updates of New Posts? Join My Email Newsletter