javascript - Check height, then add or remove class -


i'm making navigation responsive. when width above number should class, when it's below, class should removed:

var width = $("#primary-header-nav").width(); if ( width < 770) {   $('#primary-header-nav li a').addclass('box-1-9');     } else {   $('#primary-header-nav li a').removeclass('box-1-9');  } 

however, in reality, class never assigned. regardless of width.

this site if of help: http://darylkeep.com/aanbod/

try this.

$(document).ready(function(){   $(function(){     $(window).on("resize", function(){        var width = $(this).width();       var links = $('#primary-header-nav li a');        if(width < 770){         links.addclass('box-1-9');       }else{         links.removeclass('box-1-9');       }     });   }); }); 

Comments

Popular posts from this blog

cron - how to properly run Python script with crontab on every system startup -

elasticsearch - Is the order of operations guaranteed in a bulk update? -

Slow performance first queries on SQL Azure -