I'm rewriting my own javascript library to jQuery. A huge undertaking,
but hopefully it will payoff in the future :) Anyways - I'm trying to
write a function that takes the title-attribute of an image and
inserts is as a caption:

  <html>
  <head>
    <script type="text/javascript" src="jquery-1.2.6.js"></script>
    <script>
    $(document).ready(function(){
      $("img.caption").each(function(i) {
        var img_width = $(this).width();
        var img_title = $(this).attr('title');
        var img_align = $(this).attr('align');
        $(this).wrap("<div class=\"image-caption-container\" style=
\"float:" + img_align + "\"></div>");
        $(this).parent().width(img_width);
        $(this).parent().append("<div class=\"image-caption\">" +
img_title + "</div>");
      });
    });
    </script>
  </head>
  <body>
    <img src="logo.gif" class="caption" title="scripting like a
rockstar">
  </body>
  </html>

But img_width is zero (and logo.gif exists). Moving my script to the
bottom of the page (before the closing body-tag) makes no difference.
Any suggestions?

Reply via email to