0

I am trying to execute some JavaScript when my html page loads. The top method populateSelectWithDates() is called, but the jquery portion does not. Any ideas?

function doInitialPopulation() {
    //This works
    populateSelectWithDates();

    //This does not
    $(document).ready(function() {
        alert('ok');
    //Credit to: http://www.pewpewlaser.com/articles/jquery-tablesorter
        //  Adds sort_header class to ths
        $(".sortable th").addClass("sort_header");

        //  Adds alternating row coloring to table.
        $(".sortable").tablesorter({widgets: ["zebra"]});

        //  Adds "over" class to rows on mouseover
        $(".sortable tr").mouseover(function() {
            $(this).addClass("over");
        });

        //  Removes "over" class from rows on mouseout
        $(".sortable tr").mouseout(function() {
            $(this).removeClass("over");
        });

    });
}
4
  • 1
    have you included jQuery library .Check console for errors. Commented Oct 31, 2013 at 4:15
  • Did you list the jquery file before your file? Commented Oct 31, 2013 at 4:15
  • Do I do the jquery import in the external js file, or in the html file? Commented Oct 31, 2013 at 4:15
  • include it before any other javascript that wants to use jQuery. Commented Oct 31, 2013 at 4:18

2 Answers 2

1

In your HTML file, make sure you are including the scripts in this order:

<!-- first include jQuery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<!-- then include your script(s) -->
<script src="YOUR_SCRIPT.js" type="text/javascript"></script>
Sign up to request clarification or add additional context in comments.

Comments

0

I dont see any use of $(document).ready(function() { try removing it. And let us know if alert('ok') works. Also can we see the function populateSelectWithDates() ?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.