• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

242
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>
almost 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error