“Enrole a última palavra de um parágrafo em tags de span usando jQuery” Respostas de código

Enrole a última palavra de um parágrafo em tags de span usando 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>

7uc1f3r

Enrole a última palavra de um parágrafo em tags de span usando jQuery

template.html template.html template.html
Lazy Lapwing

Respostas semelhantes a “Enrole a última palavra de um parágrafo em tags de span usando jQuery”

Perguntas semelhantes a “Enrole a última palavra de um parágrafo em tags de span usando jQuery”

Mais respostas relacionadas para “Enrole a última palavra de um parágrafo em tags de span usando jQuery” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código