0

I am working in our Gmail extension right now, and given that the I have the parent Element and it looks something like below, I need to remove everything after <br clear="all" />, given that what is after may or may not exist given the users Gmail signature settings. Thoughts?

<div
    id=":93"
    class="Am Al editable LW-avf"
    hidefocus="true"
    aria-label="Message Body"
    g_editable="true"
    role="textbox"
    aria-multiline="true"
    contenteditable="true"
    tabindex="1"
    style="direction: ltr; min-height: 416px;">
    Test
    <br clear="all" />
    <div>
        <br />
    </div>
    -- <br />
    <div dir="ltr" class="m_-1358982132021700848m_4914548661371847332gmail_signature" data-smartmail="gmail_signature">
        <div dir="ltr">
            <b>Suzy Smith</b>
            <div>
                <i><a href="mailto:suzysmith@mail.com" target="_blank">suzysmith@mail.com</a></i>
            </div>
        </div>
    </div>
</div>
wscourge
  • 10,657
  • 14
  • 59
  • 80
Sandra Willford
  • 3,459
  • 11
  • 49
  • 96

1 Answers1

3

Just loop over the nextSibling and remove it.

var elem = document.querySelector('[clear="all"]')
while(elem.nextSibling) {
  elem.nextSibling.remove()
}
elem.remove()
<div
    id=":93"
    class="Am Al editable LW-avf"
    hidefocus="true"
    aria-label="Message Body"
    g_editable="true"
    role="textbox"
    aria-multiline="true"
    contenteditable="true"
    tabindex="1"
    style="direction: ltr; min-height: 416px;">
    Test
    <br clear="all" />
    <div>
        <br />
    </div>
    -- <br />
    <div dir="ltr" class="m_-1358982132021700848m_4914548661371847332gmail_signature" data-smartmail="gmail_signature">
        <div dir="ltr">
            <b>Suzy Smith</b>
            <div>
                <i><a href="mailto:suzysmith@mail.com" target="_blank">suzysmith@mail.com</a></i>
            </div>
        </div>
    </div>
</div>
epascarello
  • 204,599
  • 20
  • 195
  • 236