jQuery is not finding any elements. alert($("#testbutton").length); displays 0 every time. 
Am I doing something wrong?
My JS / jQuery code:
(function ($) {
    alert($("#testbutton").length);
}) (jQuery);
My HTML:
<html>
    <body>
        <div id="header">
            <div class="button" id="testbutton">Test</div>
        </div>
    </body>    
</html>
                When your code runs the DOM is not ready so the element doesn't exist. Did you mean to do this instead (passing a function to jQuery is a shortcut for $(document).ready(fn)):
$(function () {
    alert($("#testbutton").length);
});
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With