0
我有一個有多個類的元素。我想在點擊它時在其中一個類之間切換。如何切換指定了多個類的元素上的特定類?
<span class="icon-expand desktop-only mt8 pl4" id="toggle-site-content-width"></span>
當我點擊這個,我只是需要改變icon-expand
爲icon-reduce
,和剛剛離開的其他類原樣。
它只是在我使用$(this).toggleClass('icon-reduce')
時最後添加了該類。當我這樣做時也是如此:$(this).toggleClass('icon-expand','icon-reduce')
。
這是全碼:
$(function(){
$('#toggle-site-content-width').click(function(){ // on click
$('#site-content').children('div').toggleClass('content-align-center'); // remove this class to expand the view to full available window width
$(this).toggleClass('toggle-expand','icon-reduce'); // change the icon
$(this).trigger('resize'); // trigger the window to rearrange masonry bricks
});
});
第一個人會做什麼。或者是一個語法錯誤。? –
是的,這是在兩個類之間切換的錯誤方法。 – Felix
哦。好的。非常感謝。 – ThomasK