Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>on</code> can be used to wire up the resize and ready events just like any other event.</p> <p>So for your case, you could create a function that has the code you want to happen for <code>resize</code> and <code>ready</code>, and then pass it to both calls to <code>on</code>. </p> <p>If you want to keep your enclosing scope clean, you could do all this in an immediately executing function: </p> <pre><code>(function() { function stuffForResizeAndReady(){ // Stuff in here happens on ready and resize. } $(window).on("resize", stuffForResizeAndReady); $(document).on("ready", stuffForResizeAndReady); })(); </code></pre> <p><strong>2012-07-25</strong>: There are 2 differences to be aware of when using <code>.on()</code> to attach ready handlers:</p> <ul> <li><p>Ready handlers added via <code>$(fn)</code> and <code>$(document).ready(fn)</code> are "retro-fired" while ones added by <code>.on()</code> are not. Using those, if you add a handler after the DOM is already loaded, the fn will be fired immediately. If you add a handler via <code>.on('ready', fn)</code> <em>after</em> the DOM is loaded, it will <em>not</em> be fired by jQuery, but you can manually <code>.trigger('ready')</code> it. </p></li> <li><p>When you use <code>$(fn)</code> or <code>$(document).ready(fn)</code> to add a ready handler, the fn receives <strong><a href="http://api.jquery.com/jQuery/#jQuery3" rel="noreferrer">jQuery</a></strong> as its 1st arg, allowing the familar <code>jQuery(function($){ })</code> usage. If you use <code>$(document).on('ready', fn)</code>, the 1st arg that the fn receives is an <strong><a href="http://api.jquery.com/category/event-object/" rel="noreferrer">event object</a></strong>. In both cases <code>this</code> inside the fn is the <code>document</code>. If you were to do something abnormal like <code>$('#foo').on('ready', fn)</code> for the purpose of triggering, <code>this</code> would be the <code>#foo</code> element.</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload