Easwaran Paramasivam
asked on
JQUERY Add/remove class Issue - During Page Load
Hi experts,
I am facing an interesting some scripting issue during page load event.
am calling the below JS function when i want to sort a table either in ASC or DSC.
I am achieving this functionality by submitting the form. i tried to to sort the table based on the table sorter in JQuery. it worked very well. however there was some alignment issue that made me to use the form submission method where i will sort everything behind the browser.
Here is the issue:
HTML form element TH and its attributes:
Because of the page load with the same class attribute , am stuck and clue less. my window.load event does not have anything. even i tried adding condtional check over there. However the default class attributes comes into picture all the time. please suggest.
Thanks
I am facing an interesting some scripting issue during page load event.
am calling the below JS function when i want to sort a table either in ASC or DSC.
I am achieving this functionality by submitting the form. i tried to to sort the table based on the table sorter in JQuery. it worked very well. however there was some alignment issue that made me to use the form submission method where i will sort everything behind the browser.
Here is the issue:
HTML form element TH and its attributes:
<th id="participant_id" class="headerSortUp addLink"
style="width: 20%;height: 5px; word-wrap: break-word"
onClick="javascript:sort ();" > Name
</th>
When i call the below functionfunction sort (){
var queryString='';
if($("#participant_id").hasClass('minusLink')){
alert("am here in edit list desc");
$("#participant_id").removeClass( 'headerSortDown' ).addClass( 'headerSortUp' );
$('#participant_id').removeClass( 'minusLink' ).addClass( 'addLink' );
document.Form.editListSortOrder.val='desc';
queryString += "&editListSortOrder=" + document.Form.editListSortOrder.val;
document.Form.action = "editcontributions?"+queryString;
document.Form.submit();
}
else if($("#participant_id").hasClass('addLink')){
alert("am here in ascc");
$("#participant_id").removeClass( 'headerSortUp' ).addClass( 'headerSortDown' );
$("#participant_id").removeClass( 'addLink' ).addClass( 'minusLink' );
document.Form.editListSortOrder.val='asc';
queryString += "&editListSortOrder=" + document.Form.editListSortOrder.val;
document.Form.action = "editcontributions?"+queryString;
document.Form.submit();
}
}
Whenever i submit the form through conditional check, the page renders with the sorted result and the TH class attribute loads with "headerSortUp" . i.e default class Attribute all the time. so i am unable to perform the other form sorting. i can only perform ASC or DSC always. i need to perform this by toggleing header up and down .Because of the page load with the same class attribute , am stuck and clue less. my window.load event does not have anything. even i tried adding condtional check over there. However the default class attributes comes into picture all the time. please suggest.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.
ASKER
Thank you very much for your prompt response. This is really good. However i was able to fix the issue by passing a hidden variable and check during the page load event.
Based on the value , i was able to toggle the classes. Unfortunately there was a typo also in the id from my end.
Thanks a lot for this nice post.
Regards
Easwar