如何在jQuery中对最近的div使用最近的()

I'd like to remove the closest error-class. If I select a_1 it should remove the span after it. Same for a_2. But in div .b it should remove the error-class no matter which input I select. How can I achive this?

// doesn't work
form.each(function() {
    $(this).closest('.error').remove();
});
<div class="a">
  <input class="a_1" type="text"> <!-- if I'm here, remove next -->
  <span class="error">Error</span>
  <input class="a_2" type="text"> <!-- if I'm here, remove next -->
  <span class="error">Error</span>
</div>

<div class="b">
  <input class="b_1" type="text">
  <input class="b_2" type="text">
  <input class="b_3" type="text">
  <input class="b_4" type="text">
  <input class="b_5" type="text">
  <span class="error">Error</span> <!-- remove this -->
</div>