I do an animation button with CSS3 that will change the burger to the cross when clicking. How to convert code from pure JS to jQuery?
var toggles = document.querySelectorAll(".cmn-toggle-switch");
for (var i = toggles.length - 1; i >= 0; i--) {
var toggle = toggles[i];
toggleHandler(toggle);
};
function toggleHandler(toggle) {
toggle.addEventListener( "click", function(e) {
e.preventDefault();
(this.classList.contains("active") === true) ? this.classList.remove("active") : this.classList.add("active");
});
}
There you go.
var toggles = $('.cmn-toggle-switch');
toggles.on('click', function(e){
e.preventDefault();
$(this).toggleClass("active");
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.