首页 > 解决方案 > I need to change the first sentence only bold from paragraph using javascript and css

问题描述

Mr. MMM and Mrs. sss they are honest. They have their own car.

Here I want to change the first sentence to bold,

We have a great leader F.Rah. He is a talented boy.

Here I want to change the first sentence to bold,

We have a great leader F.Rah.

Here I want to change the sentence to bold.

标签: javascripthtmlcssnode.js

解决方案


var a = $('.last_wfp').text();
var b = a.slice(0, a.indexOf('. '));
var c = a.slice(a.indexOf('. '), a.length);

$('.last_wfp').html('<span class="last_bold">' + b + '</span>' + c);

var a = $('.last_wfp1').text();
var b = a.slice(0, a.indexOf('. '));
var c = a.slice(a.indexOf('. '), a.length);


$('.last_wfp1').html('<span class="last_bold">' + b + '</span>' + c);


var a = $('.last_wfp2').text();
var b = a.slice(0, a.indexOf('. '));
var c = a.slice(a.indexOf('. '), a.length);


$('.last_wfp2').html('<span class="last_bold">' + b + '</span>' + c);
.last_bold{
    font-weight:bold;
    padding-top:2em;
    display:inline-block;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p class="last_wfp">This is the first sentence that I want bold. This is the second sentence that I don't want that treatment. This text is lost! And then there was more.  And another sentence...</p>
<p class="last_wfp1">This is the second sentence that I want bold . This is the second sentence that I don't want that treatment. This text is lost! And then there was more.  And another sentence...</p>
<p class="last_wfp2">This is the third sentence that I want bold.</p>


推荐阅读