Search code examples
javascriptjquerycodeigniterexternal-script

Is it possible to load Jquery in the body of a page


I am using code-igniter, and some of my views require jquery. Because they must be used in multiple places they must call jquery in their file, however since they are referencing an external file, calls to $(document.ready) are evaluated before loading jquery and therefore fail. Is it possible to put jquery in the body and still have it load before an javascript is evaluated. Or alternatively, is the some way to pass the fact that jquery is required back through code-igniter into the headers, which were callled before the file in question.

In a view:

echo $this->import->js('jquery.js','jquery');
echo '<script type="text/javascript">
$(document).ready(function(){$(\'div#login.rounded\').corner();})
</script>';

You can view the page at: http://formulator.codingproject.net/content/login/

NOTE This page actually resides on my home machine, so it is expected that the recaptcha fails.


Solution

  • I guess the answer is yes. you can load the jQuery.js in your body. But you have to write your script tags only after jQuery.js declaration, if not you may end up with errors :)

    PS : please correct me If I'm wrong :)