Legs
Legs

Reputation: 41

External js file not working

I am trying to move all my jquery to an external file however it is not working. I am calling the external file after everything else but the jquery functions are not working. I think it may be because i have more than one function with $(function() { however not being proficient with jquery i do not know how to tackle this. Below is a sample of what i am trying to move over.

<script type="text/javascript">
$(function() {
    jQuery("#textsizer a").textresizer({
        target: "#size"
    });
});
</script>
<script type="text/javascript">
$(function() {
    $("#crime").validate();
    $.validator.messages.required = '<span style="color:#FE2E2E">&nbsp;Required</span>';
});
</script>

I am thinking i need to only have one with $(function() { but i don’t know what to correctly replace it with or if this is the reason the external file is not working?

Upvotes: 0

Views: 1578

Answers (2)

adeneo
adeneo

Reputation: 318342

Stick this in an external file that is included in the html document after jquery and it's plugins:

$(function() {
    $("#textsizer a").textresizer({
        target: "#size"
    });

    $("#crime").validate();
    $.validator.messages.required = '<span style="color:#FE2E2E">&nbsp;Required</span>';
});

Upvotes: 0

thebjorn
thebjorn

Reputation: 27351

You need to remove the <script> tags if it is in an external .js file.

Upvotes: 3

Related Questions