Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>Title</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <style>
- .fl {
- font-size: 2em;
- font-weight: bold;
- color: brown;
- }
- </style>
- </head>
- <body id="body">
- <p>Mano pastraipa bla bla bla </p>
- <p>Mano kita pastraipa bla bla bla </p>
- <p>Mano ajajajai pastraipa bla bla bla </p>
- <p>Mano a</p>
- <p> Mano</p>
- <p>Mano </p>
- <p> Mano </p>
- <p>Mano</p>
- <script>
- let elemList = document.getElementsByTagName("p");
- for(let i = 0; i < elemList.length; ++i){
- let elem = elemList[i];
- let text = elem.innerHTML.trim(); // eliminate spaces before and after
- let j = 0;
- let output = "";
- let tMax = text.length;
- while(text[j] != " " && j < tMax){ // skip the first word
- output += text[j];
- ++j;
- }
- if (j < tMax){ // if there was a second word
- output += text[j++]; // copy space
- output += '<span class="fl">' + text[j++] + '</span>'; // add a wrapper
- for(; j < text.length; ++j){ // copy the rest of the text
- output += text[j];
- }
- elem.innerHTML = output;
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement