Reputation: 27
I have a script which slide toggles an element when clicked. Code below:
$(document).ready(function() {
$(".accord").click(function() {
$(this).next(".accordContent").slideToggle("fast");
});
});
However, when the screen resolution is below 790px I want the element to have a default of not showing. I tried this in a media query but then the above script doesn't work when below that resolution. Guess it confuses it and need something more in JQuery. Any ideas?
Upvotes: 1
Views: 69
Reputation: 425
Try this:
$(document).ready(function() {
var winWidth = $(window).width();
if (winWidth < 790){
$(".accordContent").hide();
}
$(".accord").click(function() {
$(this).next(".accordContent").slideToggle("fast");
});
});
Upvotes: 1