1

I have a simple page

<!DOCTYPE html>
<html>     
<body>
    <input id="niceBtn" type="button" value="Nice Button" onclick="showDiv()"/>
    <div id="niceDiv" style="display:none;height:800px;width:40px;background-color:#F00;"></div>
</body>

<script type="text/javascript">
    function showDiv(){
        document.getElementById('niceDiv').style.display == "";
    }

    var resizer = function(){
        alert('Hello')
    };
    window.onresize = resizer;
</script>
</html>

When I click the button, the '#niceDiv' is shown. When the div shows, why does the resizer not fire?

Am i not attaching to the right event? I need to attach to an event which fires on dynamic DOM modification. If the size of the document changes by adding some elements either from a AJAX response, or any javascript event, I need to alert "Hello"

How can I do this? Cannot use jQuery.

EDIT: I notice that when I resize the whole browser the event fires. How can I fire it when the DOM is resized.

labroo
  • 2,629
  • 2
  • 27
  • 35
  • 1
    thats not window resize. window resize mean when you maximize or drag browser screen. – gaurang171 Aug 24 '12 at 04:09
  • Thanks keyur, I realized that. Do you have any suggestions? – labroo Aug 24 '12 at 04:12
  • yes why don't you call it on showdiv? – gaurang171 Aug 24 '12 at 04:12
  • showDiv is just an example, the DOM can be resized by many different things. – labroo Aug 24 '12 at 04:14
  • http://stackoverflow.com/questions/4561845/firing-event-on-dom-attribute-change see this link may help you. – gaurang171 Aug 24 '12 at 04:16
  • Except the plugin mentioned has not been updated in 3 years and it seems Dom mutation events are deprecated: http://stackoverflow.com/a/11106031/295783 – mplungjan Aug 24 '12 at 04:24
  • The first version of your question mentioned the HTML document being inside an iframe. Since the onresize method actually does work for iframes, I wonder if the problem isn't simply that the iframe's height doesn't resize according to the content. Perhaps if you tried to resize it through Javascript it might work, as per: http://stackoverflow.com/questions/153152/resizing-an-iframe-based-on-content – Marcelo De Polli Aug 24 '12 at 05:04

0 Answers0