Advertisement
LipeMachado

Untitled

Jan 27th, 2023
968
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.83 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.     <meta charset="UTF-8">
  6.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8.     <link rel="stylesheet" href="./style.css">
  9.     <title>Document</title>
  10. </head>
  11.  
  12. <body>
  13.     <style>
  14.         a {
  15.             color: blue;
  16.             cursor: pointer;
  17.         }
  18.     </style>
  19.  
  20.     <div class="feed-item-body mt-10 m-width-20 post-body">
  21.         <span class="short-text">Meu texto está ... <a class="read-more">ler mais</a></span>
  22.         <span class="full-text" style="display: none">Meu texto está aqui firme e forte <a class="read-less">ler
  23.                 menos</a></span>
  24.     </div>
  25.  
  26.     <div class="feed-item-body mt-10 m-width-20 post-body">
  27.         <span class="short-text">Meu texto está ... <a class="read-more">ler mais</a> </span>
  28.         <span class="full-text" style="display: none">Meu texto está aqui firme e forte <a class="read-less">ler
  29.                 menos</a></span>
  30.     </div>
  31.  
  32.     <div class="feed-item-body mt-10 m-width-20 post-body">
  33.         <span class="full-text">Meu texto pequeno</span>
  34.     </div>
  35.  
  36.     <script>
  37.         document.querySelectorAll(".post-body").forEach(function (el) {
  38.             var fullText = el.querySelector(".full-text");
  39.             var shortText = el.querySelector(".short-text");
  40.  
  41.             if (!shortText) return;
  42.  
  43.             el.querySelector(".read-more").addEventListener("click", function () {
  44.                 fullText.style.display = "";
  45.                 shortText.style.display = "none";
  46.             });
  47.  
  48.             el.querySelector(".read-less").addEventListener("click", function () {
  49.                 fullText.style.display = "none";
  50.                 shortText.style.display = "";
  51.             });
  52.         });
  53.     </script>
  54. </body>
  55.  
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement