dom-vs-jquery.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <!doctype html>
  2. <html class="no-js" lang="">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="x-ua-compatible" content="ie=edge">
  6. <title>Formation jQuery</title>
  7. <meta name="description" content="">
  8. <meta name="viewport" content="width=device-width, initial-scale=1">
  9. <link rel="manifest" href="site.webmanifest">
  10. <link rel="apple-touch-icon" href="icon.png">
  11. <!-- Place favicon.ico in the root directory -->
  12. <link rel="stylesheet" href="css/normalize.css">
  13. <link rel="stylesheet" href="css/main.css">
  14. <link rel="stylesheet" href="css/styles.css">
  15. <style type="text/css">
  16. .cell {
  17. border: 1px solid #aaa;
  18. background: #ddd;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <!--[if lte IE 9]>
  24. <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="https://browsehappy.com/">upgrade your browser</a> to improve your experience and security.</p>
  25. <![endif]-->
  26. <!-- Add your site or application content here -->
  27. <div class="container">
  28. <ul>
  29. <li><a href="index.html">Accueil</a></li>
  30. <li><a href="dom-vs-jquery.html">DOM vs jQuery</a></li>
  31. </ul>
  32. <h1>DOM vs jQuery</h1>
  33. <h2>DOM</h2>
  34. <div id="dom"></div>
  35. <h2>jQuery</h2>
  36. <div id="jquery"></div>
  37. </div>
  38. <script src="js/vendor/modernizr-3.5.0.min.js"></script>
  39. <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
  40. <script>window.jQuery || document.write('<script src="js/vendor/jquery-3.2.1.min.js"><\/script>')</script>
  41. <script src="js/plugins.js"></script>
  42. <script src="js/main.js"></script>
  43. <!-- Google Analytics: change UA-XXXXX-Y to be your site's ID. -->
  44. <script>
  45. window.ga=function(){ga.q.push(arguments)};ga.q=[];ga.l=+new Date;
  46. ga('create','UA-XXXXX-Y','auto');ga('send','pageview')
  47. </script>
  48. <script src="https://www.google-analytics.com/analytics.js" async defer></script>
  49. <script>
  50. // DOM: Crée table de 5 lignes x 3 colonnes
  51. var dom = document.getElementById('dom');
  52. var table1 = document.createElement('table');
  53. table1.id = 'table1';
  54. dom.appendChild(table1);
  55. for(var i = 0 ; i < 5 ; i++) {
  56. var row = document.createElement('tr');
  57. table1.appendChild(row);
  58. for (j = 0 ; j < 3 ; j++) {
  59. var cell = document.createElement('td');
  60. cell.classList = 'cell';
  61. row.appendChild(cell);
  62. cell.innerHTML = 'Cellule ' + i + ',' + j;
  63. }
  64. }
  65. // Puis change leur background
  66. function changeCellsBackgroundDom() {
  67. var table1 = document.getElementById('table1');
  68. var cells = table1.getElementsByClassName('cell');
  69. for(c = 0 ; c < cells.length ; c++) {
  70. cells[c].style.background = '#acf';
  71. }
  72. }
  73. setTimeout(changeCellsBackgroundDom, 1000);
  74. // jQuery: Crée table de 5 lignes x 3 colonnes
  75. var jquery = $('#jquery');
  76. var table2 = $('<table></table>').appendTo(jquery);
  77. table2.attr('id', 'table2');
  78. for(var i = 0 ; i < 5 ; i++) {
  79. var row = $('<tr></tr>').appendTo(table2);
  80. for (j = 0 ; j < 3 ; j++) {
  81. var cell = $('<td></td>').appendTo(row);
  82. cell.addClass('cell');
  83. cell.html( 'Cellule ' + i + ',' + j );
  84. }
  85. }
  86. // Puis change leur background
  87. function changeCellsBackgroundJQuery() {
  88. $('#table2 .cell').css('background','#caf');
  89. }
  90. setTimeout(changeCellsBackgroundJQuery, 1000);
  91. </script>
  92. </body>
  93. </html>