dimanche 4 février 2018

If statement inside jQuery

I am having a small issue with jQuery.

I have an if statement that will alert me if I've clicked a 'circle' or a 'square'. The part that alerts if I've clicked a square works, but not the part that alerts if I've clicked a circle.

<body>
        <div id="circle" ></div>
        <div class="square" ></div>
        <div class="square" ></div>
        <script type="text/javascript">
            $("div").click(function() {
                if($(this).attr("id") === true) {
                    alert("You have clicked a: " + $(this).attr("id"));
                } else {
                    alert("You have cicked a: " + $(this).attr("class"));
                }
            });
        </script>
    </body>

Aucun commentaire:

Enregistrer un commentaire