jquery - Get innertext of a <td> and append new row with results -


i have data formatted table. want setup onclick button url of link inside 1 of td's in row , load results in row below. here's example of row. assume there no id's in table.

<tr>     <td>title of something</td>     <td><a href="link_to_something.html">link</></td>     <td><button onclick="load_file(this.??);">show page</button></td> </tr> 

the javascript need to:

function load_file( , ) {     //  url in second <td>     //  urlencode url     //  append new <tr><td colspan="3"></td></tr> below     //  load some_file.php , pass variable (file_url) , value (urlencoded) using .load method in jquery , load results newly appended <td>     } 

i have read on .load method in jquery. possible load results if td has no id?

i guess set id table elements if proves difficult without id's, trying keep php script simple , "as needed" stuff jquery.

here's example of sorts can use

your html. notice added class button, , type.

<table> <tr>     <td>title of something</td>     <td><a href="link_to_something.html">link</></td>     <td><button class='thebutton' type='button'>show page</button></td> </tr> </table> 

your js

$('.thebutton').click(function(){     var $this = $(this);     var $td   = $this.parent('td');     var url = $td.prev().children('a:first').attr('href');     var row = '<tr><td class="data" colspan="3"></td></tr>';     $td.parent().after(row);      //var data  = getdata(); //use whatever method want - $.post, $.get, $.load     var data  = 'hello';     $td.parent().next().children('td:first').html(data); }); 

http://jsfiddle.net/jomanlk/4d39n/

you'll need change load data whichever way want, else works.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -