html - how to retrieve table values using jquery? -


how retrieve email value when click on <a> tag "add friend" , when email value change <a> tag "add friend" "friend request sent" ?

sorry.... bad english.

find-friends.html

<!doctype html> <html lang="en"> <head>     <meta charset="utf-8">     <title>find friends</title> </head> <body>     <h4><a href="php/logout.php">log out</a> </h4>      <table class="details" align="center">       </table>      <script src="js/jquery-1.10.1.min.js"></script>     <script type="text/javascript" src="js/find-friends.js"></script> </body> </html> 

find-friends.js

$(document).ready(function() {     $.getjson('php/find-friends.php', function( data ) {          $.each(data, function(key, value) {             var tr=$('<tr></tr>');             $.each(value, function(key, val) {                  if (key === 'name') {                     // $('#name').append('name:'+ ' ' + val);                     $('<td>'+"name : "+val+ '&nbsp;&nbsp;&nbsp;&nbsp;' +'</td>').appendto(tr);                 }                  if (key === 'mobile') {                     $('<td>'+"mobile : "+val+ '&nbsp;&nbsp;&nbsp;&nbsp;' +'</td>').appendto(tr);                 }                  if (key === 'email') {                     $('<td>'+"email : "+val+'&nbsp;&nbsp;&nbsp;&nbsp;'+'</td>').appendto(tr);                     // $('<td>'+'<a href=# class=link>'+'add friend'+'</a>'+'</td>').appendto(tr);                     $('<tr><td>'+'<a href="#" class="link">'+"add friends"+'</a>'+'</td>').appendto(tr);                 }             });             tr.appendto('.details');         });     }); }); 

add email data attribute link:

if (key === 'email') {     $('<td>'+"email : "+val+'&nbsp;&nbsp;&nbsp;&nbsp;'+'</td>').appendto(tr);     // $('<td>'+'<a href=# class=link>'+'add friend'+'</a>'+'</td>').appendto(tr);     $('<tr><td>'+'<a href="#" class="link" data-email="' + val + '">'+"add friends"+'</a>'+'</td>').appendto(tr); } 

then can use retrieve it:

$(".details").on("click", ".link", function() {     var email = $(this).data("email");     sendfriendrequest(email);     $(this).text("friend request sent"); }); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -