$('body').layout is not a function

4.1k views Asked by At

I'm using the jQuery UI Layout plugin and I keep getting this error in Firebug: $('body').layout is not a function. I also get the same error in IE8 and below.

Obviously, it's being caused by the line where I initiate the layout UI in my scripts file:

$('body').layout({ *options here* });

Is there a way to prevent this error from showing? I'm pretty sure I need the BODY selector for this particular plugin to run.

** SOLUTION **

As the helpful answers say below, I had this line: $('body').layout({ *options here* }); BEFORE I included my jQuery and jQuery UI Layout Plugin files. Once I put the body.layout after those two inclusions, the error went away.

2

There are 2 answers

0
Christoph On BEST ANSWER

You seem to either

1) have not included the plugin properly (script tag missing/typo in the url, included it before loading jquery itself, whatever else could go wrong)

 or

2) calling $("body").layout too early - wrap it with $(document).ready(function() { });

it should be

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

...

<script type="text/javascript">
   $(document).ready(function() {
      $("body").layout() // will work now
   });
</script>

1
Daniel Li On

Make sure you're including the lines:

<SCRIPT type="text/javascript" src="/path/to/jquery-latest.js"></SCRIPT>
<SCRIPT type="text/javascript" src="/path/to/jquery.layout-latest.js"></SCRIPT>

Prior to the code you placed in your question. Otherwise, layout will have been undefined before use.