简体   繁体   中英

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)

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

应该读:

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

你缺少jquery选择器:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM