Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing style inside jQuery selector dynamically

I have a div and I am trying to display a text with bold font as follows:

$('#div').text("data between "+ fromdate + "to" + todate).css({'text-align':'centre'});

How do I display only "fromdate" and "todate" in bold font?

like image 913
user1907849 Avatar asked Jul 20 '26 02:07

user1907849


2 Answers

Use .html(), and wrap the text in <b> (if it is presentational) or <strong> tags:

$('#div')
    .html("data between <b>" + fromdate + "</b> to <b>" + todate + "</b>")
    .css("text-align", "center");

And centre should be center.

like image 136
Sverri M. Olsen Avatar answered Jul 22 '26 16:07

Sverri M. Olsen


set as html then assign and filter as class, finally set the css to the filtered result

$('#div').html("data between <span class='bold'>"+ fromdate + "</span>to<span class='bold'>" + todate + "</span>").css({'text-align':'center'}).filter( ".bold" ).css( "font-weight", "bold" );
like image 27
gurvinder372 Avatar answered Jul 22 '26 15:07

gurvinder372



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!