1.) Assume I have a (HTML) page which contains none, one or more occurencies of

...
<p>
....
<br>
<br>
</p>
...


If a <br> tags follows another, second <br> element with only whitespaces in between
then BOTH <br> tags should be deleted.

How can I perform this replacement/deletion with javascript?

2.) Assume I have a (HTML) page which contains none, one or more occurencies of

....
<h2>....</h2>
<br>
...

Similar to 1.) when the closing tag </h2> is followed by a <br> (only whitespaces are allowed between) element, then the <br> tag should be deleted.

How can I perform this replacement/deletion with javascript?

Thank you
Peter