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>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);
});
});span{
color:red;
}
Also in CSS:
- css parent selector
- chat bot with a floating button html and css
- how to center text in css
- scss ::after
- !important in css
- bootsrap buttons
- css border style
- forms html css
- how to make input in angular optional
- css transform transition
- hover transition css
- how to apply different properties to different paragraphs in css
- css sticky header with nav bar
- css gradient border
- css change class name start with
- striped tables css
- css grid align
- HTML & CSS: Design and Build Web Sites
- css keyframes
- round button css
- adding css to html body
- removing space between words css
- how to get my footer to the bottom of the page using css
- text underline hover css