Hey there! I've got a question for you about the .toggle() function:
Is there a way to make it toggle only once?
I have an event tied to window resize and I want my element to be visible or hidden based on this.
I'm aware that achieving this with media queries and CSS is quite simple (and probably the best option), but I'm curious about how to do it using jQuery.
I attempted to use the .one() method, but couldn't quite grasp how it's supposed to work.
Below is the snippet of my jQuery code:
jQuery(document).ready(changeClass);
jQuery(window).resize(changeClass);
function changeClass() {
if($(window).width() < 805){
$('.test').one(toggle());
}
Can you point out what I might be doing wrong?
And in case someone encounters a similar issue in the future, here's the solution using pure CSS:
@media(max-width:805px)
{
.test{
display:none;
}
}