$('.class').each( function() { let thisEl = $(this); thisEl.html(thisEl.html().replace(/(\S+)\s*$/, '<span>$1</span>')); });