Search code examples
jquerytexthyperlinkcellhtml-table

jquery, dynamically create link from text in td cell


I have a question currently up at: scan image, create links from content (php hopefully)

Since I'm working in ms publisher, I can remove the map image and just keep the #'d boxes. Saving just those as .htm I end up with the following code:

<!--[if gte vml 1]><![if mso | ie]><v:shape id="_x0000_s1039" type="#_x0000_t201" style='position:absolute;left:311.27pt;top:110.81pt;width:11.34pt;height:9pt; z-index:7;mso-wrap-distance-left:2.88pt;mso-wrap-distance-top:2.88pt; mso-wrap-distance-right:2.88pt;mso-wrap-distance-bottom:2.88pt' stroked="f" strokecolor="black [0]" insetpen="t" o:cliptowrap="t">
<v:stroke color2="white [7]">
<o:left v:ext="view" color="black [0]" color2="white [7]" weight="0"/>
<o:top v:ext="view" color="black [0]" color2="white [7]" weight="0"/>
<o:right v:ext="view" color="black [0]" color2="white [7]" weight="0"/>
<o:bottom v:ext="view" color="black [0]" color2="white [7]" weight="0"/>
<o:column v:ext="view" color="black [0]" color2="white [7]"/>
</v:stroke>
<v:shadow color="#ccc [4]"/>
<v:textbox inset="0,0,0,0">
</v:textbox>
</v:shape><![endif]><![endif]-->

<table v:shapes="_x0000_s1039" cellpadding=0 cellspacing=0 width=15 height=12 border=0 dir=ltr style='width:11.34pt;height:9.0pt;border-collapse:collapse; position:absolute;top:110.81pt;left:311.27pt;z-index:7'>
<tr>
<td width=15 height=12 bgcolor=white style='width:11.3385pt;height:9.0pt; padding-left:.1417pt;padding-right:.1417pt;padding-top:.1417pt;padding-bottom:.1417pt;background:white;border:solid blue .25pt'>
<p class=MsoNormal style='text-align:center;text-align:center'><span lang=en-US style='font-size:5.0pt;font-family:Arial;language:en-US'><span dir=ltr></span>185</span></p>
</td>
</tr>
</table>

I'm looking (as in the previous question) to create links from the #'s in the cell (in this instance it is 185. I have far too many to manually do this on an ongoing basis, so am searching for a way to do it with code.

I found this code with jQuery which should grab the text from the :

 $('#myTable tr').each(function() {
     var 
    $tds = $(this).find('td');
     if($tds.length != 0) {
     var 
    $currText = $tds.eq(0).text();

    alert('Curr Source Language: ' + $currText);

     }
     });

I'm not quite sure how to implement the jQuery above either. I would like the entire table to be a link (not just the inner #'s). So if the 'get text' works, then I'd like to wrap the entire table with: -- everything inbetween as above code --

I hope that makes some sense. Thanks for any suggestions.


Solution

  • You need a way of finding the value in the table im using lang=en-US as a selector. Then you need to build a url and change the page

    $(function (){
            // Assign click event on any table
            $('table').click(function(){
               // Get Value
               var val = $(this).find('[lang=en-US]').text();
               // Change Page
               window.location.href = "http://gotothislink_" + val + ".jpg"
            });
    });
    

    Working example http://jsfiddle.net/blowsie/tSMnd/