Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

light switch button error code

I have dis code from a website bet the .post gives a error and can solve it can some one help me?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>light</title>
</head>
<body>
<span id="main_light_switcher">
        <span id="check_inside">
            <span id="trigger_on" class="inside">
                <img src="img/light-bulb-icon-off-16.png" border="none" width="16" height="16"
                     style="vertical-align: middle; margin-right: 2px;
                     cursor: pointer; padding-bottom: 3px;"
                     alt="Light Off">
                <span style="cursor:pointer; color:#999;">Light Off</span>
            </span>
        <span id="trigger_off" class="inside_off" style="display: none">
            <img src="img/light-bulb-icon-on-16.png" border="none" width="16" height="16"
                 style="vertical-align: middle; margin-right: 2px; cursor: pointer; padding-bottom: 3px"
                 alt="Light On">
            <span style="cursor:pointer; color: #fdb619">Light On</span>
            </span>
        </span>
    </span>
    <script
        src="http://code.jquery.com/jquery-3.2.1.min.js"
        integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
        crossorigin="anonymous"></script>
    <script src="app.js"></script>
</body>
</html>```

```javaScript
jQuery(window).ready(function($){

    if ($('body').find('.post').length > 0) { $("#main_light_switcher").fadeIn(); } else { $("#main_light_switcher").hide(); }

    $("#trigger_on").click(function() {

        $('.post').parents().css("z-index", "auto");
        $(".post").css("background-color", "");
        $(".post").animate({"padding" : 0}, "slow");

        $(".post").expose({
            closeOnEsc: true,
            closeOnClick: true,
            closeSpeed: 'fast',
            color: '#000000',
            loadSpeed: 'slow',
            opacity: 0.95,
            zIndex: 9998,
            onClose: function() {$("#trigger_off").hide(); $("#trigger_on").show(); $(".post").animate({"padding-top" : 0, "padding-right" : 0, "padding-bottom" : 0, "padding-left" : 0}, "slow"); $(".post").css("background-color", "");}
        });

        $("#trigger_on").hide(); $("#trigger_off").show().fadeTo('fast', 0.5);});
    $("#trigger_off").click(function() {$.mask.close(); $("#trigger_off").hide(); $("#trigger_on").show(); $(".post").animate({"padding-top" : 0, "padding-right" : 0, "padding-bottom" : 0, "padding-left" : 0}, "slow"); $(".post").css("background-color", "");});

});```

1 Answer

Steven Parker
Steven Parker
231,271 Points

Most of this script deals with element(s) with a class of "post", but there are none like that in this HTML code. With none present, the very first thing the script does is hide the rest of the HTML elements.

Also, this script contains a call to "expose", which I believe is part of another software package which does not appear to be loaded here.

So overall, it appears that this code is still just incomplete.

And when quoting code, those three back-ticks need to be on a line by themselves.