Struggling with the css.class & ajax.call~~PLZ help!

Struggling with the css.class & ajax.call~~PLZ help!

I'm very new for jquery & js, so I'd like to be someone like u guys, so there's the question:

I have a menu list (four h5s) to call 4 pages for each h5.

I want the h5 clicked to get a current class when its call is completed, and the previous one come back to be with a link class, and the page called in the container.

Now I got the code:

HTML

  1. <div>
  2. <h5 id='menu' onclick=changeDivClass(this.id,0,1)>Menu1</h5>
  3. <h5 id='menu' onclick=changeDivClass(this.id,1,1)>Menu2</h5>
  4. <h5 id='menu' onclick=changeDivClass(this.id,2,1)>Menu3</h5>
  5. <h5 id='menu' onclick=changeDivClass(this.id,3,1)>Menu4</h5>
  6. </div>
  7. <div id="row1">
  8. </div>

.js

  1. function changeDivClass(id,act,row){
  2.  var menuID = 'h5#'+id;
  3.  var action = new Array('act1,'act2','act3','act4')
  4.  var row = 'row'+row;
  5.  $(document).ready(function(){
  6.   $('h5').click(function(){
  7.    $.ajax({
  8.     url:"aaa.php",
  9.     data:'&act='+action[act],
  10.     success:function(html){$('div#'+row).replaceWith(html);
  11.     $(menuID+'.current).removeClass('current');
  12.     $(menuID).addClass('current');
  13.     }
  14.     });//ajax
  15.     });//click
  16.     });//ready
  17. }

Now, the problem are:

  • The h5 can't change back from current;
  • ajax calls only once -- the second click doesn't work.

I know there's somethin is logicaly wrong is the addClass, but I don't know how to fix it.

Can anyone help me with that!?~~Thanks~~