Simple script, but could I have done it better.

Simple script, but could I have done it better.

I developed a very small script to look through a sharepoint announcement for attachment links, then convert them to thumbnails when the page loads. It all works, but I'm looking for feedback on what could have been done better:

HTML (don't have much control over it, sharepoint):
  1. <div style="width:100%;display:block;overflow:auto;" class="imthumbs"></div>
  2. <div style="padding: 6px 4px;width:100%;" class="imattach"><b>Attachments:</b><br/>
  3. <div style="margin-left:12px;margin-top:5px;">
  4. <TABLE border=0 cellpadding=0 cellspacing=0 id=idAttachmentsTable>
  5. <TR><TD class="ms-vb"><span dir="ltr"><a tabindex=1 href="/968/Mucker 2015 Adam.jpg">Mucker 2015 Adam.jpg</a></span></TD></TR>
  6. <TR><TD class="ms-vb"><span dir="ltr"><a tabindex=1 href="/968/Mucker 2015 Beta Amy.jpg">Mucker 2015 Beta Amy.jpg</a></span></TD></TR>
  7. <TR><TD class="ms-vb"><span dir="ltr"><a tabindex=1 href="/968/Mucker 2015 Cathy.jpg">Mucker 2015 Cathy.jpg</a></span></TD></TR>
  8. </TABLE>
  9. </div>
  10. </div>
and the jquery:
  1. $(document).ready(function(){

  2. $(".imattach").find("a").each(function(){
  3. var url = $(this).attr('href');
  4. if (url.toLowerCase().indexOf(".jpg") >= 0 || url.toLowerCase().indexOf(".gif") >= 0 || url.toLowerCase().indexOf(".png") >= 0)
  5. {
  6. var count = $(this).closest(".imattach").find("a").length;
  7. if (count < 2)
  8. {
  9. var imglink = '<a href="' + url + '"><img src="' + url + '" class="thumbsingle"/></a>';
  10. $(this).closest(".imcont").find(".imbody").prepend(imglink);
  11. }
  12. else
  13. {
  14. var imglink = '<a href="' + url + '"><img src="' + url + '" class="thumbinline"/></a>';
  15. $(this).closest(".imcont").find(".imthumbs").append(imglink);
  16. }
  17. }
  18. });
  19. });
Looking to get better, thanks a lot!