Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1.  
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <title>js</title>
  6.  
  7. <style>
  8. .color-yellow {
  9. color: yellow;
  10. }
  11. .color-light-green {
  12. color: lightgreen;
  13. }
  14. </style>
  15.  
  16. <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
  17. <script>
  18. $(document).ready(function() {
  19. var texts = [];
  20. $('div').each(function(index) {
  21. console.log(index);
  22. if ((index + 1) % 2 == 0) {
  23. var txt = "<span style='color:yellow'>"
  24. txt = txt + $(this).text();
  25. txt = txt + "</span>";
  26. $(this).html(txt);
  27. } else {
  28. var txt = "<span style='color:lightgreen'>"
  29. txt = txt + $(this).text();
  30. txt = txt + "</span>";
  31. $(this).html(txt);
  32.  
  33. }
  34. texts.push($(this).text());
  35. });
  36. var new_html = '';
  37. for (var i = texts.length - 1; i >= 0; i--) {
  38. new_html = new_html + texts[i] + '<br />';
  39. }
  40. console.log(new_html);
  41. $('.larger-div').html(new_html);
  42. });
  43. </script>
  44.  
  45. </head>
  46.  
  47. <body>
  48. <div>text</div>
  49. <div>text1</div>
  50. <div>text2</div>
  51. <div>text3</div>
  52. <div>text4</div>
  53. <div>text5</div>
  54. <div>more difficult</div>
  55.  
  56. <hr />
  57.  
  58. <div class='larger-div'>
  59.  
  60. </div>
  61.  
  62. </body>
  63.  
  64. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement