I am using the following line of code to change the font color of a text element.
However, the element can be multiple lines, eg
Line1
Line2
When I run the code the result is
Line1Line2
This is what I am currently using;
$w(“#text1”).html=<p style="color: #FFFFFF">${$w("#text1").text}</p>
;
The problem with your code is that you are using the html property to set the text content of the element. This will replace the existing text content, including any formatting.
To change the text color without losing formatting, you need to use the style property. The style property can be used to set any CSS property, including the color property.
The following code will change the text color of the element without losing formatting:
$w(“#text1”).style = “color: #FFFFFF”;
This code will set the text color of the element to white. The formatting of the text will be preserved.
Here is an example of how the code would work:
Line1
Line2
If you run the code, the text color of the element will be changed to white, but the formatting of the text will be preserved.
Here is the output of the code:
Line1
Line2
As you can see, the formatting of the text is preserved. The text is still on two lines, and the line breaks are still present. Hope it helps.
Hi PeterGray,
Firstly, thank you for responding and taking the time to lay out the response in such a helpful manner.
Unfortunately, it does not work for me. When I use the code above I get a syntax error, in that the .style has a red underline with the message - Property ‘style’ does not exist on type ‘Text’.
If it makes a difference, the text box is connected to a dataset, the dataset field is plain Text (not Rich Text etc).
![](https://us1.discourse-cdn.com/wix/original/3X/1/9/1976b6564d09d8271d34968f8239f2b37c1418d8.png)