2016-11-05 6 views
1

Ich brauche etwas Hilfe mit jquery.Ich brauche meine Menüschaltfläche von "Menübutton" in "x" ändern (die Schaltfläche Abbrechen ist). Aber das Problem ist, dass jquery nur die Klasse hinzufügt Konsole und in Inspektor, und es auch tut ändern Menüsymbol .. sagt nur, dass die Klasse hinzugefügt wird ... Hier ist mein Code:Jquery nur hinzufügen, ohne Klasse zu entfernen

$('.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: Ich arbeite auf Wordpress .

+2

haben Sie einen Tippfehler. '$ ('Tablet-Symbol ') addClass (' form-acive');' <- bei im aktiven fehlen, wenn das ist das Problem :) – ilwcss

+0

schön Fang ilwcss! – Medda86

+0

Das ist der ganze Fehler! @ilwcss – baao

Antwort

1

Credits ilwcss

Problem: ist mit dieser Linie

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

Ein Tippfehler Fehler .. form-acive muss form-active

Nur toggleClass() benutzen, um die Aufgabe zu simplyfy .

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

+0

@ilwcss du bist ein Adler. :) –

Verwandte Themen