Reputation: 79
I use jQuery to change h1
header after end of a game and I have the following line of code:
$('h1').text(winningPlayer+" has won!").css("fontSize", "55px");
The question is, how can I set a different color just for winningPlayer
part of text??
Upvotes: 1
Views: 1288
Reputation: 36594
Wrap the winningPlayer
in <span>
and change .text()
to .html()
. Below is the demo
let winningPlayer = "John"
$('h1').html(`<span style="color:blue">${winningPlayer}</span> has won!`).css("fontSize", "55px");
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h1></h1>
Upvotes: 6