Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save DevShahidul/88b8413ced54c62655e60de0556ba892 to your computer and use it in GitHub Desktop.

Select an option

Save DevShahidul/88b8413ced54c62655e60de0556ba892 to your computer and use it in GitHub Desktop.
$('.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