-1

I'm having the hardest time finding a way to match and remove the text I've been asked to remove.

I can't just match the exact string because it's different every time, but it's always between the same known chars.

    <h1 class="art-PostHeader" style="border-bottom:solid 1px; border-bottom-color:#4D909D;"><a href="/content/library-closed-14" title="Library Closed">Building Closed</a></h1>
   Code to Remove <form action=

So, while the "Content to be removed" can be anything alpha or numeric, it will always be between </h1> and <form

There should be a way to write a jQuery remove() or replace() function to match it, but I can't figure it out. I've tried regular expressions but I'm not the best at those.

Jason
  • 396
  • 4
  • 19

1 Answers1

1

You can reference the nachor tag and get the Next sibling and set the node's value to nothing.

$("h1.art-PostHeader")[0].nextSibling.nodeValue = ""
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1 class="art-PostHeader" style="border-bottom:solid 1px; border-bottom-color:#4D909D;"><a href="/content/library-closed-14" title="Library Closed">Building Closed</a></h1> CONTENT TO BE REMOVED<form action="get"></form>
epascarello
  • 204,599
  • 20
  • 195
  • 236
  • 1
    Just FYI the `a` appears to be inside a `h1` tag (although the code is incomplete) so the content to be removed wouldn't be a sibling of the `a` element. – Rory McCrossan Nov 16 '15 at 18:38
  • Correct, I could not get this code to work.. Im updating the question with the full html. – Jason Nov 16 '15 at 18:42
  • $("#calpopup-body h1")[0].nextSibling.nodeValue = "" - This worked! – Jason Nov 16 '15 at 18:44