I have the following HTML and JavaScript:

```
<!DOCTYPE html>
<html>        
<head>
    <script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
</head>
<body>
    <a href="#foo" id="bar">Something</a>
    <div id="foo></div>
    <script>
        $(function() {
            $link = $("#bar");
            $link[0].click(function() {
                alert("Whatever.");
            });
        });
    </script>
</body>
</html>

```

[This article](https://makandracards.com/makandra/17267-trigger-a-link-s-click-action-with-javascript) explains the approach. However it's not working - no alertbox shows. Any ideas?