Home > Software engineering >  Remove span elements with the same Ids and only let one remain
Remove span elements with the same Ids and only let one remain

Time:11-07

I have an HTML string. i want to select all span elements and remove spans with the same IDs and only let one of them remain in the string. The text between the span elements should not be deleted.

The spans with the same IDs are all after each other. The remained one should wrap all the removed ones text.

e.g:

Input:

<p>
  Hi,<span id="1">this is just a simple and we</span>
  <span id="1">want to save me for becuase i had a lot of</span>
  <span id="1">presure on and i want to live a betteer life.            
  • Related