jQuery code to delete all spans with same content but keep one

Posted by Axel on Stack Overflow See other posts from Stack Overflow or by Axel
Published on 2010-04-05T01:08:52Z Indexed on 2010/04/05 1:13 UTC
Read the original article Hit count: 371

Filed under:
|

Hello,

Say i have the following html:

<span class="fruit">Apple</span>
<span class="fruit">banana</span>
<span class="fruit">Apple</span>
<span class="fruit">Apple</span>
<span class="fruit">orange</span>

I tried different methods but it didn't work, I want a jQuery code to remove all (.fruit) spans with same content but keep one (the first if possible), so i will end up with the following:

<span class="fruit">Apple</span>
<span class="fruit">banana</span>
<span class="fruit">orange</span>

Thank you

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery