Introduction

jQuery has some predefined functions. Using predefined functions, we can perform our client-side tasks. jQuery append function is used to bind a table on client-side.
Why we will bind on client side
  • Any operation we will perform in the client-side is more likely to be faster than the server-side because the operation is happening in the client browser.
  • We can give an attractive look to the UI during client-side operation.
  • Reduce the server side coding.
Example
Here we have an array named bykeList, which contains three brand names.
var bykeList=["Hero","Honda","Suzuki"]
Now we will bind this array to a Table using jQuery append function.
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>Tooltip Example</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
  8. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  9. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
  10. </head>
  11. <body>
  12. <div class="container">
  13. <table class="table table-striped">
  14. <thead>
  15. <tr>
  16. <th>Sl.No</th>
  17. <th>Byke Name</th>
  18. <tr>
  19. </thead>
  20. <tbody id="tblBykeLists"><tbody>
  21. </table>
  22. </div>
  23. <script>
  24. $(document).ready(function(){
  25. var bykeList=["Hero","Honda","Suzuki"];
  26. if(bykeList.length>0){
  27. for(i=0;i<bykeList.length;i++){
  28. var html="<tr><td>"+Number(1+i)+"</td><td>"+bykeList[i]+"</td></tr>";
  29. $("#tblBykeLists").append(html);
  30. }
  31. }
  32. });
  33. </script>
  34. </body>
  35. </html>
In the above code, first, I checked the bykeList length. If the length is greater than 0 then there is some data, iterate through the data and bind it in a table.
Summary
In this blog, I discussed how we can use jQuery append function. I hope it was useful for you.