Advertisement
Guest User

Untitled

a guest
Jul 16th, 2015
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.66 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta charset="UTF-8">
  5.         <title>Document</title>
  6.     </head>
  7.     <body>
  8.         <table>
  9.             <thead>
  10.                 <tr>
  11.                     <th>Name</th>
  12.                     <th>Company</th>
  13.                     <th>E-Mail</th>
  14.                 </tr>
  15.             </thead>
  16.             <tbody>
  17.                 <tr>
  18.                     <td>Sergey brin</td>
  19.                     <td>Google</td>
  20.                     <td class="email">
  21.                         <a class = "link" href= "www.gmail.com" > sergey.brin@gmail.com </a>
  22.                         <button class = "edit_button" type="button" style = "float:right" >Edit !</button>
  23.                     </td>
  24.                 </tr>
  25.                 <tr>
  26.                     <td>Elon Musk</td>
  27.                     <td> Amazon </td>
  28.                     <td class="email">
  29.                         <a class = "link" href = "www.spacex.com">elon.musk@spacex.com </a>
  30.                         <button class= "edit_button" type="button" style = "float:right">Edit !</button>
  31.                     </td>
  32.                 </tr>
  33.                 <tr>
  34.                     <td> Bill Gates </td>
  35.                     <td> Microsoft </td>
  36.                     <td class="email">
  37.                         <a class = "link" href = "www.microsoft.com"> bill.gates@hotmail.com </a>
  38.                         <button class="edit_button" type="button" style = "float:right">Edit !</button>
  39.                     </td>
  40.                 </tr>
  41.             </tbody>
  42.         </table>
  43. </html>
  44. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  45. <script>
  46.     $(function(){
  47.         $('.edit_button').click(function(){
  48.             console.log($(this).siblings().text());
  49.             modifications($(this));
  50.         });
  51.     });
  52.    
  53.     function modifications(cell){
  54.         var form = '<form> <input type="text" id = "newText" size = "30" value='+cell.siblings().text()+'></form>';
  55.  
  56.         cell.parent('td').append(form).focus();
  57.         cell.parent().children('.link').toggle();
  58.         $('#newText').keypress(function (e) {
  59.  
  60.             if (e.which == 13) {
  61.                 console.log("form submitted");
  62.                 e.preventDefault();
  63.  
  64.                 var new_text = cell.parent('td').children('#newText').val();
  65.                 //Show hyperlink with new value
  66.                 cell.parent().children('.link').toggle();
  67.                 cell.parent().children('.link').text(new_text);
  68.                 //Hide text box
  69.                 cell.parent().children('.newText').hide();
  70.             }
  71.         });  
  72.     }
  73.    
  74. </script>
  75. </body>
  76. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement