0

I have my own drop down navigation working, so when a user clicks on one of the links a page overlay will appear. I just need when they click again the page overlay removes.

Here is my code to add the overlay

$('#nav li a').on('click', function(){
    $('#page-overlay').addClass('active').siblings().removeClass('active');
});

And a working DEMO is here - http://dsm.fishtankcreative.co.uk/

I just need help for when a user clicks off the navigation the page overlay class disappear.

Thanks in advanced.

1 Answer 1

1

Use toggleClass()

$('#nav li a').on('click', function(){
    $('#page-overlay').toggleClass('active').siblings().removeClass('active');
});

Note: I don't think there is a need to use .siblings().removeClass('active'), as you are not adding the active class to any other elements

Sign up to request clarification or add additional context in comments.

2 Comments

Thats great thanks, but one question if you don't mind. link if you click on Kingfisher in the navigation it works but if you go from kingfisher to DSM then click off it doesn't work 100%
I got it working by adding two page overlays then doing this $('#nav li#dsm').on('click', function(){ $('#page-overlay').toggleClass('active'); $('#page-overlay2').removeClass('active'); }); $('#nav li#king').on('click', function(){ $('#page-overlay2').toggleClass('active'); $('#page-overlay').removeClass('active'); });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.