Horje
Wrap the last word of a paragraph in span tags using jQuery Code Example
Wrap the last word of a paragraph in span tags using jQuery
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>Phasellus sit amet auctor velit, ac egestas augue.</p>
<script>
jQuery(document).ready(function($){  
		
	$('p').html(function(){	
		// separate the text by spaces
		var text= $(this).text().split(' ');
		// drop the last word and store it in a variable
		var last = text.pop();
		// join the text back and if it has more than 1 word add the span tag
		// to the last word
		return text.join(" ") + (text.length > 0 ? ' <span class="last">'+last+'</span>' : last);   
	});

});
</script>
<style>
span{
color:red;
}
</style>





Html

Related
a href type submit Code Example a href type submit Code Example
html5 video player autoplay Code Example html5 video player autoplay Code Example
font myriad pro html Code Example font myriad pro html Code Example
tailwind Code Example tailwind Code Example
tailwind css link Code Example tailwind css link Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7