0

I have a "button-bar" div that I only want to show once the user has clicked on a "settings" button. I have set the button-bar div to display:none in my css. Unfortunately, when the settings button is clicked, the div shows up for a split second, then goes away. Does anyone know why this might be happening? My current code:

$(document).ready(function() {
    $('#settings').on('click', function() {
        $('#button-bar').css('display', 'inline-block');
    });
});

3 Answers 3

1

The problem is your href="" are empty, it is reloading the page. Put hashtags in them. href="#"

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

Comments

0
$(document).ready(function() {
    $('#settings').on('click', function() {
        $('#button-bar')show();
    });
});

or maybe

$(document).ready(function() {
        $('#settings').click(function() {
            $('#button-bar')show();
        });
    });

5 Comments

This should work, although the .css("","") should have too. If this does not work, try posting a fiddle with more of your code, could be something else, not just this function.
It appears to have the same problem -- it shows for a split second right after I release my mouse button and then disappears.
have you tried .click(function() instead of .on("click" function() ??
I have; it has the same issue. I've been told the .on() function was more elegant so I went with that.
You are going to have to post more of your code in a fiddle, there should be nothing wrong with any of this.
0

You need to add a "return false;" at the end of your function, otherwise it follows the html link, which is empty.

(edit: The href="#" will work to fix your error, but it will also make the page jump to the top when clicked. The return false; will stop this happening if that is a problem. )

Comments

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.