web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / HtmlText: Is it possib...
Power Apps
Answered

HtmlText: Is it possible to use Replace and Substitute functions on a HTML string?

(0) ShareShare
ReportReport
Posted on by 13

Hi guys, hope you're all well!

 

I have a chunk of HTML (with some in-line CSS) within a HtmlText control. I'd like to be able to replace parts of the code on a button click. For example, if I click on a button I'd replace the string 'color:red', with 'color:blue'. 

 

I've tried putting the string into a variable and have tried Replace/Substitute with no luck. 

 

Any guidance would be appreciated, thank you!

Categories:
I have the same question (0)
  • Verified answer
    dan-finan Profile Picture
    13 on at

    Sorry guys, I may have jumped the gun on this one. Using a variable to replace the colour name does actually work however it won't display until the entire web page is refreshed. 

  • AndrewR1 Profile Picture
    1,572 Moderator on at

    To achieve dynamic replacement of parts of an HTML string with inline CSS in a HtmlText control, you can follow these steps:

    • Create Variables: Create two variables to hold your HTML content and the modified HTML content:
      ClearCollect(HtmlContent, "<div style='color:red;'>Your content here</div>");
      ClearCollect(ModifiedHtmlContent, HtmlContent);

    Here, HtmlContent holds the original HTML content, and ModifiedHtmlContent will hold the modified HTML.

    • Replace Function: Use the Replace function to replace the desired parts of the HTML string. In this example, replace "color:red;" with "color:blue;":
      OnSelect:
      UpdateContext({
      ModifiedHtmlContent: Replace(HtmlContent, "color:red;", "color:blue;")
      })

    This will update the ModifiedHtmlContent variable with the modified HTML string.

    • Bind HtmlText Control: Bind your HtmlText control to the ModifiedHtmlContent variable:
    • HtmlText.Text = ModifiedHtmlContent

    if this helps can you hit the thumbs up and if it’s resolved your issue set this as the solution 

     

    Many thanks 

    Andrew 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 536

#2
WarrenBelz Profile Picture

WarrenBelz 426 Most Valuable Professional

#3
Haque Profile Picture

Haque 305

Last 30 days Overall leaderboard