I'm adjusting the width of a div using media queries. I need the page to react when that div changes width.
I've used .resize
, however, that triggers twice and causes an issue when the user interacts with the div further. I can't use .live()
since that requires the user to interact to achieve the desired effect. Finally, Ive looked into DOMSubtreeModified
but that has been depreciated.
In simple terms this is what I want to do:
$('#element').watchForChange(function(){
*...do stuff here when the change happens...*
});
Thanks for your assistance.
----- EDIT -------
Let me clarify a common issue I see with resize with this example:
<div id="box"></div>
<span id="button">Open</span>
In the above example assume the #box
is 400x400 and in the "open" state (display:block)
. 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 ($('#button').click(function(){...});)
The issue I keep sing is when I would click "open" the box opens then closes. The second click works fine.
Jquery is retaining the second call in the event handler. I can't unbind it since I'll need to check the size again.
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.