Search code examples
javascriptjquerytagshead

Jquery head tags issue


I have gone crazy for hours testing some jquery scripts in my site and nothing was working, while it would work on Fiddles...

So here is what I have in my :

Then I have a script as below but I can't get it to work!!!

<script type="text/javascript">
$(":checkbox").bind("click", function(event) {
    if ($(this).is(':checked')) {
        $(".itemBox:not(#" + $(this).val() + ")").hide();
        $(".itemBox[id='" + $(this).val() + "']").show();
    } else {
        $(".itemBox").show();
    }
});
</script>

Solution

  • You have wait for the document to load before you can bind events to it.

    jQuery provides an easy way to do that, by calling the ready method on the document, and putting all your code inside that function:

    jQuery(document).ready(function($) {
        // All of your code should go in this function
    });