2016-11-05 8 views
1

jqueryのヘルプが必要です。「メニューボタン」から「x」(キャンセルボタン)に変更するにはメニューボタンが必要ですが、jqueryはクラスを追加するだけですコンソールとインスペクタで、それがさえdoesntの変更メニューアイコン.. のみクラスが追加されていることを言います... は、ここに私のコードです:Jqueryはクラスを削除せずに追加する

$('.tablet-icon').click(function() { 
 
    if ($('.tablet-icon').hasClass('form-active')) { 
 
    $('.tablet-icon').removeClass('form-active'); 
 
    console.log('is-removed'); 
 
    return false; 
 
    } else { 
 
    $('.tablet-icon').addClass('form-acive'); 
 
    console.log('is-added'); 
 
    return false; 
 
    } 
 
});
.tablet-icon { 
 
    position: absolute; 
 
    padding: 0; 
 
    margin: 0; 
 
    right: 0; 
 
    left: 85%; 
 
    top: 22px; 
 
    width: 40px; 
 
} 
 
.tablet-icon:before { 
 
    width: 100%; 
 
    font-size: 1.6em; 
 
    display: block; 
 
    font-family: "ElegantIcons"; 
 
    font-weight: bold; 
 
    text-align: center; 
 
    content: "\61"; 
 
} 
 
.tablet-icon:before::after { 
 
    clear: both; 
 
    content: ""; 
 
    display: table; 
 
} 
 
.tablet-icon.form-active:before { 
 
    font-size: 1.6em; 
 
    line-height: .9em; 
 
    content: "\4d"; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<span class="tablet-icon"></span>

PM:イムは、ワードプレスに取り組んで。このライン

$('.tablet-icon').addClass('form-acive');

誤植で..ですform-aciveform-active

だけでタスクをsimplyfyするtoggleClass()を使用している必要があります。問題

ilwcssへ

+2

あなたはタイプミスがあります( 'タブレットのアイコン ')。 '$ addClass(' フォームaciveを');' < - 問題のthats場合は、アクティブにで行方不明:) – ilwcss

+0

素敵なキャッチilwcss! – Medda86

+0

それは全体のエラーです! @ilwcss – baao

答えて

1

クレジット。

$('.tablet-icon').click(function() { $(this).toggleClass('form-active'); });

+0

@ilwcssとしてあなたがワシであることに感謝します。 :) –

関連する問題