# Problem with jQueries replaceWith method

**URL:** <https://forum.kirupa.com/t/problem-with-jqueries-replacewith-method/288041>\
**Category:** web dev\
**Created:** [May 9, 2009, 11:10pm UTC](https://forum.kirupa.com/t/problem-with-jqueries-replacewith-method/288041 "2009-05-09T23:10:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![trevorsaint](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/trevorsaint/32/268_2.png) [@trevorsaint](https://forum.kirupa.com/u/trevorsaint)\
**Post date:** [May 9, 2009, 11:10pm UTC](https://forum.kirupa.com/t/problem-with-jqueries-replacewith-method/288041/1 "2009-05-09T23:10:16Z")

</div>

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:-

```auto
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
