Marc Marc - 1 year ago 56
jQuery Question

Nav disappeares when clicking on a button, this only needs to be at < 767

My navigation disappeares when clicking on a button, this needs to happen only when viewport is < 767px

larger as 767px this doesn't need to be hidden.


var $nav = $('#nav').
prepend('<div class="responsive-nav" style="display:none">Navigation</div>').
on('click', '.responsive-nav, ul a', function(evt) {
if ( === 'a' && $(window).innerWidth() >= 767) {


if ($(window).innerWidth() < 767) {
$('nav ul li').css('display','block');
$('nav ul').hide()
} else {
$('nav ul li').css('display','inline-block');
$('nav ul').show()




I have made an example here to see whats happening:

Answer Source returns the tag name in Caps.


....On HTML elements in DOM trees flagged as HTML documents, tagName returns the element name in the uppercase form.

So, here it returns A, change your if() to

if ( === 'A' .....)


if( === 'a'

Updated Fiddle

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download