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
- <div>
- <h5 id='menu' onclick=changeDivClass(this.id,0,1)>Menu1</h5>
- <h5 id='menu' onclick=changeDivClass(this.id,1,1)>Menu2</h5>
- <h5 id='menu' onclick=changeDivClass(this.id,2,1)>Menu3</h5>
- <h5 id='menu' onclick=changeDivClass(this.id,3,1)>Menu4</h5>
- </div>
- <div id="row1">
- </div>
.js
- function changeDivClass(id,act,row){
- var menuID = 'h5#'+id;
- var action = new Array('act1,'act2','act3','act4')
- var row = 'row'+row;
- $(document).ready(function(){
- $('h5').click(function(){
- $.ajax({
- url:"aaa.php",
- data:'&act='+action[act],
- success:function(html){$('div#'+row).replaceWith(html);
- $(menuID+'.current).removeClass('current');
- $(menuID).addClass('current');
- }
- });//ajax
- });//click
- });//ready
- }
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~~