Es gibt false
für jedes einzelne Protokoll auf der Konsole aus. Das Umschalten funktioniert einwandfrei, wenn Sie auf die Schaltfläche für den Navigationslink und die Schaltfläche "Abbrechen" klicken. Ich habe mir this question angesehen und alle Vorschläge ausprobiert, hatte aber immer noch das selbe Problem.hasClass() gibt immer false (jquery) zurück, auch wenn es umgeschaltet wird
// add new photo toggle
$('#click_new_photo a').click(function() {
console.log($(".content").hasClass('show-new-photo'));
$(".content").find(".new-photo").toggleClass('show-new-photo');
console.log($(".content").hasClass('show-new-photo'));
});
$("#cancel_add_new_photo").click(function() {
console.log($(".content").hasClass('show-new-photo'));
$(".new-photo").toggleClass("show-new-photo");
console.log($(".content").hasClass('show-new-photo'));
});
.new-photo {
width: 300px;
height: 200px;
border-radius: 5px;
background: #34609d;
box-shadow: 1px 1px #d6d6d6;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
z-index: 100;
transition: opacity 0.5s ease;
opacity: 0;
}
.show-new-photo {
opacity: 1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<nav>
<ul>
<li id="click_new_photo"><a href="#">New Photo</a></li>
</ul>
</nav>
<div class="content">
<div class="new-photo">
<button id="cancel_add_new_photo">Cancel</button>
</div>
...
</div>
...
</body>
in Ihrer Demo gibt es keine Klasse ' 'Show-new-photo'' in Inhalt – guradio
Auch der Selektor‚Inhalt‘ist ganz deutlich von‚.content‘ – Pointy