Created
August 23, 2017 23:49
-
-
Save cron64/46975e118d218ae802e36dd040548f1f to your computer and use it in GitHub Desktop.
JS: First-last word selection
This file contains 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
$(".last-word").html(function(){ | |
var text= $(this).text().trim().split(" "); | |
var last = text.pop(); | |
return text.join(" ") + (text.length > 0 ? " <span class='red'>" + last + "</span>" : last); | |
}); | |
$(".first-word").html(function(){ | |
var text= $(this).text().trim().split(" "); | |
var first = text.shift(); | |
return (text.length > 0 ? "<span class='red'>"+ first + "</span> " : first) + text.join(" "); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment