Weird problem with unwrap()

Weird problem with unwrap()

Hi,
 
I have an img wrapped with <a> when clicking the img 2 things should happen :
  1. unwrap the <a> tag around the img
  2. replace the img.
my code looks like this:
  1. $imgNext.unwrap('<a>');
    $imgNext.attr('src',$imgNext.attr('src').replace('but_next_on','but_next_dis'));
Two strange things happen when this code runs:
  1. the img is replaced but the unwrap does not work
  2. if i copy paste the unwrap (so now it is called twice) the unwrap works.

Any ideas?