Problem with jQueries replaceWith method

Hi all.

I am having some issues with the replaceWith method in jQuery.

Simply changing the class is fine, and my function works as you would expect. But when I change html with the replaceWith method I run into problems:-

var checkStatus = function() {		
		
 if (iIndex == iMin) {			
  $('#options a#prev').replaceWith('<span id="prev"></span>');			
 } else {			
  $('#options a#prev').replaceWith('<a href="#" id="prev"></a>');
 };
		
 if (iIndex == iMax) {			
  $('#options a#next').replaceWith('<span id="next"></span>');			
 } else {			
  $('#options a#next').replaceWith('<a href="#" id="next"></a>');
 };
		
};

//Previous item
$('#options a#prev').click(function() {	
			
 if (iIndex > iMin) {		
  iIndex --;
 } checkStatus();
			
});	
	
//Next item
$('#options a#next').click(function() {			
			
 if (iIndex < iMax) {
   iIndex ++;			
 }; checkStatus();
			
});

What I am expecting from my script is that when the user gets to the maximum, the link turns into a span element. And if the user goes back a step then the span becomes an active link.

Any help would be good.

Thanks