Today I have a question for the best syntax on Js :
Here is the usual version
function resize() {
if ($(window).width() < 960) {
$('. slect span').click(function () {
$('.home-footer').toggleClass('open-in-mob');
});
} else {
$('.home-footer').removeClass('open-in-mob');
$('. slect span').click(function () {
$('.home-footer').toggleClass('open-in-mob');
});
}
}
$(document).ready(function () {
$(window).resize(resize);
resize();
});
And here here is an other version that works, but, I would have your opinion:
if (matchMedia('only screen and (max-width:959px)').matches) {
$(".slect span").click(function(event) {
$(this).parents(".home-footer").addClass("open-in-mob");
});
}
If you think that an other syntax is better, please share :) thanks