views:

61

answers:

1

Something should trigger, no? I get not supported in IE8 and nothing happening in Fx 3.6.10

<html>
<head>
<script src="http://code.jquery.com/jquery-1.4.2.js"&gt;&lt;/script&gt;
<script>


// modified from http://pragmatec.blogspot.com/2009/06/google-toolbar-style-and-tooltip.html
jQuery(function($){
  $.fn.dommodhandler = function(options){
    function setListeners(){
      if (typeof (this.onpropertychange) == "object"){
        $('#innerDiv').bind('propertychange',function(e){
          $('#msgDiv').html(this.id+' changed</br/>');
        });
      }
      else if ($.browser.mozilla){
      $('#msgDiv').html("bind");
        $('#innerDiv').bind('DOMAttrModified',function(e){
          $('#msgDiv').html(this.id+' changed</br/>');
        });
      }
      else {
        $('#msgDiv').html('not supported in this browser');
        return false;
      }
    }
    return setListeners();
    }
  }
);
$(document).ready(function(){
  $.fn.dommodhandler ();
});

</script>
</head>
<body>
<div id="wrapper">
<a href="#" onClick="document.getElementById('innerDiv').height='300px';document.getElementById('innerDiv').innerHTML=new Date(); return false">Click</a>
  <div id="outerDiv">
    <div id="innerDiv">Hello</div>
  </div>
  <div id="msgDiv"></div>      
</div>  

</body>
</html>

UPDATE: Still not happy... Anyone have any suggestions to detect when something (ajax) change the actual height of a div due to larger or smaller content

A: 

If you actually change an attribute, the event fires (FF 3.6.10): http://jsfiddle.net/Nw4rA/

Thomas
Interesting - that did not trigger when I changed the height - so do you have a suggestion as to how I can trigger the script when the content changes the size of the div since onresize is not triggered in non-IE browsers
mplungjan
That's tricky, afaik. Would it suffice for you to listen to the window's resize event? $(window).bind('resize', function(event) {...}) ? If not, you might have to work with custom events that you fire whenever you change your div's size.
Thomas
That is what I thought I had done above. And it is to be triggered when the div's size is changed, not when I change the div's size. That was just a demo
mplungjan