DavidMcHale92
DavidMcHale92

Reputation: 61

Setting CSS properties through Javascript if/else statements using Jquery

I'm trying to create a button in a website right now that will adjust the size of a toolbar based on the visibility of two other columns. So far I've written the following, but as soon as I add if/else statements into the mix, the Javascript will not execute.

Here's my code thus far:

<script>
        $("#categorizedBlogsToggle_button").click(function() {
            if ($("#uncategorizedBlogsContainerDiv".css("display") == "none")){
            $("#categorizedBlogsContainerDiv").toggle( "fast", function() {
            });
                $("#blogToolbar").css({
                    "width": "82%",
                    "left": "5%"
                });
        }
            else{
                $("#categorizedBlogsContainerDiv").toggle( "fast", function() {
                });
                $("#blogToolbar").css({
                    "width": "70%",
                    "left": "20%"
                });
            }
        });
    </script>

Thank you!

Edit: Updated with jQuery selector and fixed brackets, but it still isn't working for me.

I'm not sure if it would affect the syntax I'd use, but the attributes I'm trying to modify in these elements are derived from an external style sheet. (In this case /blog.css)

Upvotes: 0

Views: 1526

Answers (2)

loopforever
loopforever

Reputation: 495

            if ("#uncategorizedBlogsContainerDiv".css("display") == "none"){

Should read:

            if ($("#uncategorizedBlogsContainerDiv").css("display") == "none"){

Upvotes: 2

Tomanow
Tomanow

Reputation: 7367

You are missing jquery selector:

if ($("#uncategorizedBlogsContainerDiv").css...

Upvotes: 0

Related Questions