Transform <span class="XX">text</span> into <a class="XX">text</a>

Transform <span class="XX">text</span> into <a class="XX">text</a>

Hello,

I'd just want to transform for some obscur reason all my 
  1. <span class="XX">text</span> 
( where XX is unknown)
into 

  1. <a class="XX">text</a>

I do a wheel like


  1. $('span').each(function(index, value){
  2.                         }

that works, I could do a 

  1. $(this).replaceWith($('<a>' + this.innerHTML + '</a>'));

but how to keep the attributes ?

Thank you in advance for your help