0

I have a function which makes a GET request and returns a string of HTML content looking like this:

<div class="mx_Parent">
    <a href="" target="_blank" rel="noopener">
        <img src="themes/img/logos/logo-letter.png" alt="" class="mx_Logo"/>
    </a>
    <h1 class="mx_Header_title">_t("Welcome to Test")</h1>
    <div class="mx_ButtonGroup">
        <div class="mx_ButtonRow">
            <a href="#/login" class="mx_ButtonParent mx_ButtonSignIn mx_Button_iconSignIn">
                <div class="mx_ButtonLabel">_t("Sign In")</div>
            </a>
            <a href="#/register" class="mx_ButtonParent mx_ButtonCreateAccount mx_Button_iconCreateAccount">
                <div class="mx_ButtonLabel">_t("Create Account")</div>
            </a>
        </div>
    </div>
</div>

This content is then rendered by React, however, I need to somehow delete this part:

<a href="#/register" class="mx_ButtonParent mx_ButtonCreateAccount mx_Button_iconCreateAccount">
    <div class="mx_ButtonLabel">_t("Create Account")</div>
</a>

I'm not exactly sure how would I edit this since it's just a big string. Maybe using .replace() ?

Onyx
  • 5,186
  • 8
  • 39
  • 86
  • Do you have control on the API that returns this HTML? If yes, then maybe you can try passing some query params and then on the backend you can return HTML as you want whenever you receive this query with your API calls. If not, then you need to parse your HTML strings to DOM elements using some JS libraries and then you can remove the node of your register link. See here - https://stackoverflow.com/questions/3103962/converting-html-string-into-dom-elements – Gaurav Sep 20 '21 at 10:37
  • @Gaurav I don't have control on the API unfortunately, I have to do it on the front-end – Onyx Sep 20 '21 at 11:22
  • 1
    Could you add a CSS rule on `mx_Button_iconCreateAccount` class to set the element `display: none`. – net.uk.sweet Sep 20 '21 at 12:18
  • Why do you want to delete that part? To not show the register link? You can do via CSS also as suggested above. – Gaurav Sep 21 '21 at 12:15

0 Answers0