using java script in html how do you compare a table row wit

using java script in html how do you compare a table row with a time stamp with another table row with a timestamp. the one with the greater time stamp replaces the other.

Solution

<html>
   <head>
       <script>
           function changeToMax(){
               var d1 = document.getElementById(\"table1\").textContent;
               var d2 = document.getElementById(\"table2\").textContent;
               var dt1 = new Date(d1);
               var dt2 = new Date(d2);
               if(dt1<dt2){
                   document.getElementById(\"table1\").textContent = d2;
               }
               else{
                   document.getElementById(\"table2\").textContent = d1;
               }

           }
       </script>
   </head>
   <body>
       <table>
           <tr>
               <td>Time stamp</td>
           </tr>
           <tr>
               <td id=\"table1\">2016/10/30 09:34:42</td>
           </tr>
       </table>
       <table>
           <tr>
               <td>Time stamp1</td>
           </tr>
           <tr>
               <td id=\"table2\">2016/10/31 09:34:42</td>
           </tr>
       </table>

       <button onclick=\"changeToMax()\" value=\"ChangeTime\">ChangeToMax</button>
   </body>
</html>

using java script in html how do you compare a table row with a time stamp with another table row with a timestamp. the one with the greater time stamp replaces

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site