Thanks, setting the width explicitly helps. I am disappointed, though.
Is there a way to read an image's width even without it being set
explicitly?

Secondly, I have a lot of little functions I use on my website, like
these. Is there a way how I should rewrite them to jQuery?

function select_goto(obj, base_url) {
  var selected = obj.options[obj.selectedIndex].value, url = '';
  url = (selected == 'ignore') ? base_url : base_url + '?type=' +
selected;
  document.location.href = BASE_HREF + url;
}

function limitChars(obj) {
  obj.value = obj.value.replace(/[^-a-z0-9_]/ig,'');
  obj.value = obj.value.toLowerCase();
}

function arg(index) {
  var url = String(document.location).split("//");
  var pad = url[1].split("?");
  var arg = pad[0].split("/");

  return arg[index];
}

On 15 nov, 17:50, Karl Swedberg <[EMAIL PROTECTED]> wrote:
> could be that the images aren't finished loading by the time you're  
> trying to get their width. Maybe putting your script inside a window  
> load rather than document ready would help. I'm guessing, too, that  
> the images don't have a width and height attribute explicitly set in  
> the html.
>
>   $(window).bind('load', function() {
>     // your code ...
>
> });
>
> --Karl
>
> ____________
> Karl Swedbergwww.englishrules.comwww.learningjquery.com
>
> On Nov 15, 2008, at 8:55 AM, Fluffy Convict wrote:
>
>
>
> > 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