I’m having trouble some jquery and was wondering if you could help.
I have a menu with a dropdown and would like to change the position of the dropdown depending on which list item it is AND how wide the drop down is, this is what I’ve got so far…
$(document).ready(function() {
var subnavWidth = $('.sub-nav-wrapper').width();
if(subnavWidth > 900) {
$('.sub-nav-wrapper').addClass('two-column-offers');
} else if (subnavWidth > 800) {
$('.sub-nav-wrapper').addClass('one-column-offers');
} else if(subnavWidth > 600) {
$('.sub-nav-wrapper').addClass('offers');
} else if(subnavWidth > 500) {
$('.sub-nav-wrapper').addClass('two-column');
} else if(subnavWidth > 300) {
$('.sub-nav-wrapper').addClass('one-column');
}
});
but only takes into account the first list item in the menu and applies the relevant class to each of the sub navigations. I want it to check the width for each sub navigation not just the first one and then apply the class to that particular sub nav.
I hope that makes sense.
1 Answer