我想添加一个类并根据 div 的 id 删除一个类
<div class="coll-Expa-wrapper">
<div class="PMessages_toolbar_collapseAll " id="collapseAllPrivateMessage">
Collapse all
</div>//<------when user clicks it class .PMessages_toolbar_collapseAll should be removed and .semi-active class should be added
<div class="semi-active" id="expandAllPrivateMessage"
Expand all
</div>>//<------when user clicks it .semi-active class should be removed and .PMessages_toolbar_expandAll class should be added
$(document).ready(function(){
$('.semi-active').bind('click',classtoggle)
});
function classtoggle()
{
var toggler=$('.semi-active').attr('id');
if(toggler =="expandAllPrivateMessage" )
{
$(this).removeClass('semi-active').addClass('PMessages_toolbar_expandAll');
$('.PMessages_toolbar_collapseAll').removeClass('PMessages_toolbar_collapseAll').addClass('semi- activ');
}
else if(toggler =="collapseAllPrivateMessage" )
{
$(this).removeClass('semi-active').addClass('PMessages_toolbar_collapseAll');
$('.PMessages_toolbar_expandAll').removeClass('PMessages_toolbar_expandAll').addClass('semi-active');
}