Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the best way to detect when a div changes width with jQuery?
    primarykey
    data
    text
    <p>I'm adjusting the width of a div using media queries. I need the page to react when that div changes width.</p> <p>I've used <code>.resize</code>, however, that triggers twice and causes an issue when the user interacts with the div further. I can't use <code>.live()</code> since that requires the user to interact to achieve the desired effect. Finally, Ive looked into <code>DOMSubtreeModified</code> but that has been depreciated.</p> <p>In simple terms this is what I want to do:</p> <pre><code>$('#element').watchForChange(function(){ *...do stuff here when the change happens...* }); </code></pre> <p>Thanks for your assistance.</p> <p>----- EDIT -------</p> <p>Let me clarify a common issue I see with resize with this example:</p> <pre><code>&lt;div id="box"&gt;&lt;/div&gt; &lt;span id="button"&gt;Open&lt;/span&gt; </code></pre> <p>In the above example assume the <code>#box</code> is 400x400 and in the "open" state <code>(display:block)</code>. When the window resizes to 800px I want the box to close (display:none). The "open" button will use jquery to open the box again <code>($('#button').click(function(){...});)</code></p> <p>The issue I keep sing is when I would click "open" the box opens then closes. The second click works fine.</p> <p>Jquery is retaining the second call in the event handler. I can't unbind it since I'll need to check the size again.</p> <p>I'm not using an open close function. Rather I'm using a next button on a slider. I need the items to reset back to the beginning on that resize. I can get them to reset, no problem. The issue is: the second click of "next" resets it.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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