Last active
April 3, 2018 13:50
-
-
Save DevShahidul/88b8413ced54c62655e60de0556ba892 to your computer and use it in GitHub Desktop.
Stacoverflow site link >>> https://stackoverflow.com/questions/10495574/target-the-last-word-within-an-h1-element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $('.book-consultation em a').html(function(index, curHTML) { // This function for select last word | |
| var text = curHTML.split(/[\s-]/), | |
| newtext = '<span class="last-word">' + text.pop() + '</span>'; | |
| return text.join(' ').concat(' ' + newtext); | |
| }); | |
| // Another way to select First word and last word ========================= | |
| $("#lastWord").html(function(){ // Class or id can be use | |
| var text = $("#lastWord").text().split(" "); // All text convert to array. | |
| var last = text.pop(); // Select last wrod. | |
| var first = text.shift(); // Select first word. | |
| var firstW = first.innerHTML = '<span class="firstWord">' + first + '</span>'; // Make wrapper of first wrod | |
| var lastW = last.innerHTML = '<span class="lastWord">' + last + '</span>'; // Make wrapper of last wrod. | |
| return firstW + " " + text.join(" ") + " " + lastW ; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment