javascript - Get text from <tr> and add to img alt in another <tr> -


i want copy text blogger blogspot caption table , add img alt, appear in fancybox slideshow title/caption.

so, html have :

<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; text-align: right;"><tbody> <tr>           <td style="text-align: center;"><a href="url"><img align="right" alt="" src="url" title="ghostly waves in valle de rocas" width="320" /></a></td>         </tr> <tr>           <td class="tr-caption" style="text-align: center;">this caption</td>         </tr> </tbody></table> 

and script is:

   $("tr-caption").each(function(){      var caption = $(this).text();       if (caption && caption !== ''){          $(this).parent(img).attr('alt', caption );      } }); 

and output i'd hope for....

<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; text-align: right;"><tbody> <tr>           <td style="text-align: center;"><a href="url"><img align="right" alt="this caption" src="url" title="ghostly waves in valle de rocas" width="320" /></a></td>         </tr> <tr>           <td class="tr-caption" style="text-align: center;">this caption</td>         </tr> </tbody></table> 

but it's not working...

here's jsfiddle: http://jsfiddle.net/ncqw2/6/

any appreciated! taking time look!

replacing

$(this).parent(img).attr('alt', caption ); 

with

$(this).parent().prev().find('img').attr('alt', caption ); 

should it.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -