LeTung LeTung - 10 months ago 37
CSS Question

Jquery launch as soon as the page loads

I have a jquery.

$(window).on('load resize', function() {
var dm3Width = $('.dm3').width()

Demo Here: https://jsfiddle.net/veusr0xn/

It changes
, based on the width of
. But it runs only after I adjusted the size of the window. How does it run as soon as the page loads?

Thank so much.


Define your query under $( document ).ready(function() Scope so when document will load your query will automatically work

   $( document ).ready(function() {
     var width=$(".dm3").width();
     $(window).resize(function() {
       var dm3 = $('.dm3').width();