tonyf
tonyf

Reputation: 35587

Include jQuery document.ready() as an include file

Am I able to include as an include, an external jquery.dialog.js file that consists of the following?

$(document).ready(function(){ 

    $(function() {
      location.hash = 'PAGETOP';
    });

   $("#dialogou").dialog({
            autoOpen: false,
            closeOnEscape: false,
            resizable: false,
            modal: true,
            draggable: true,
            position:  ["center", 100],
            buttons: {
              'Ok': function() {               
                      $(this).dialog("close"); 
                      closeReq();
                    }
        }
    });  
});

and then pass this in using the script include notation:

<script type="text/javascript" src="../jquery.dialog.js"></script>

This doesn't seem to work for me.

Upvotes: 1

Views: 3231

Answers (2)

Justin Johnson
Justin Johnson

Reputation: 31300

I believe $(document).ready(function(){}); and $(function() {}); (a short-hand version) are equivalent, so you should simplify it to just:

$(document).ready(function(){
   location.hash = 'PAGETOP';

   $("#dialogou").dialog({
            autoOpen: false,
            closeOnEscape: false,
            resizable: false,
            modal: true,
            draggable: true,
            position:  ["center", 100],
            buttons: {
              'Ok': function() {               
                      $(this).dialog("close"); 
                      closeReq();
                    }
        }
    });  
});

Also, install Firebug so you can see what's being included and from where. It will tell you if you are including your script wrong (probably a 404).

Upvotes: 0

Tzury Bar Yochay
Tzury Bar Yochay

Reputation: 9004

as long as you include the jQuery's .js file before this dialog one, it should work

Upvotes: 1

Related Questions