1

I have this code in my script:

$(document).ready(function() {
    $('*').not('div#user').click(function() {
        $('div#userSettings').hide();
    });
    $('div#user').click(function() {
        $('div#userSettings').toggle();
        $('div#profileSettings').toggleClass('rotate');
    });
});

I need the div#userSettings to be hidden whenever anything but it's button or itself is clicked, and I want it to appear only when I click on the div#user.

the toggleclass does still work in this, just that the div#userSettings does not appear at all

1 Answer 1

3

You can stop the event propagation

$(document).ready(function () {
    $(document).click(function (e) {
        $('#userSettings').hide();
    })
    $('#user').click(function (e) {
        e.stopPropagation();
        $('#userSettings').toggle();
        $('#profileSettings').toggleClass('rotate');
    });
    $('#userSettings').click(function (e) {
        e.stopPropagation();
    });
});

Demo: Fiddle

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

1 Comment

Jep... That worked.. Thank you very much. I will mark this as answer as soon as it lets me :D

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.