Advertisement
irmantas_radavicius

Untitled

Feb 13th, 2022
1,273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.20 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <title>Title</title>
  5.     <meta charset="UTF-8">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <style>
  8.         .fl {
  9.             font-size: 2em;
  10.             font-weight: bold;
  11.             color: brown;
  12.         }
  13.     </style>
  14.    
  15. </head>
  16. <body id="body">
  17.     <p>Mano pastraipa bla bla bla </p>
  18.     <p>Mano kita pastraipa bla bla bla </p>
  19.     <p>Mano ajajajai pastraipa bla bla bla </p>
  20.     <p>Mano a</p>
  21.     <p> Mano</p>
  22.     <p>Mano </p>
  23.     <p> Mano </p>
  24.     <p>Mano</p>
  25.     <script>
  26.         let elemList = document.getElementsByTagName("p");
  27.         for(let i = 0; i < elemList.length; ++i){          
  28.            
  29.             let elem = elemList[i];
  30.             let text = elem.innerHTML.trim(); // eliminate spaces before and after
  31.            
  32.             let j = 0;
  33.             let output = "";           
  34.             let tMax = text.length;
  35.             while(text[j] != " " && j < tMax){ // skip the first word
  36.                 output += text[j];
  37.                 ++j;               
  38.             }
  39.             if (j < tMax){ // if there was a second word
  40.                 output += text[j++]; // copy space
  41.                 output += '<span class="fl">' + text[j++] + '</span>'; // add a wrapper
  42.                 for(; j < text.length; ++j){ // copy the rest of the text
  43.                     output += text[j];
  44.                 }              
  45.                 elem.innerHTML = output;
  46.             }
  47.            
  48.         }
  49.     </script>
  50. </body>
  51. </html>
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement