Is it possible to load jQuery in the body of the page

I use igniter code and some of my views require jquery. Since they must be used in several places, they must call jquery in their file, however, since they refer to 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 load it before javascript is processed. Or, alternatively, this is a way to convey the fact that jquery is required back through the code header to the headers that were programmed before this file.

In 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 is actually located on my home machine, so recaptcha is not expected to succeed.

+4
source share
6 answers

I think yes. you can load jQuery.js in body . But you should write script tags only after declaring jQuery.js , if not you may encounter errors :)

PS : please correct me if I am wrong :)

+2
source

jQuery really needs to be called on the head element. Here is how you would do it conditionally (unchecked).

In your controller, every function that needs jQuery should have:

 $data['need_jquery'] = true; $this->load->view('header'); 

In the header view:

 <head> <? if($need_jquery) { ?> <script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js" /></script> <? } ?> </head> 
+2
source

Sounds like you're using PHP? If so, create a static method that returns this string, but only if it has not yet been included in this request. Then you can make sure that it is turned on only once.

+1
source

My site is similar. What I'm doing is a single headline that loads on all pages. In this header, I do if($this->uri->segment(2) == 'controller') . Then I load jQuery and some scripts if necessary for this controller.

0
source

I think it would be nice if jQuery is included in the tag of each page, in addition, you can use the mini version of jQuery, which is not so heavy.

0
source

Maybe I'm wrong. But when I look at the source code and follow the jquery file: http://www.formulator.com/assets/scripts/jquery/jquery.js I get the message "the page cannot be found". Therefore, I suppose this could be a problem. Maybe your php output does not include the correct domain / subdomain?

0
source

All Articles