Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

109
Views
Turn string into HTML document, remove element by class and then turn it back into HTML string?

I have a string containing HTML and I'm trying to remove a specific element from it. Right now I'm trying the following approach - I'm using const doc = new DOMParser().parseFromString(body, 'text/html'); to turn the string into HTML document and now I'm trying to somehow remove this element from the HTML document:

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

Then I'd want to turn it back into a string. I'm not quite sure how to both remove the element from the HTML document and then turn it back into a string.

<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>
7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs