• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can i dynamically load the jQuery javascript library without using ajax

 
Ranch Hand
Posts: 110
Android Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey I came across the need to load jQuery based on an event after a basic html page had already loaded. I don't want to load jQuery the moment my Html page loads for whatever reason and at some moment or on some event i wants to load jQuery how can i do it.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems like an odd thing to do, but you can construct a script tag for the jQuery library and add it to the DOM.
 
Shashank Agarwalg
Ranch Hand
Posts: 110
Android Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can i call the perticuler jquery function in Html page at perticular moment.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like at *what* "particular moment"? I mean, jQuery is just a library--you can call its methods whenever you want.
 
Shashank Agarwalg
Ranch Hand
Posts: 110
Android Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the moment i means that at perticular event. This had to be done synchronously with any other code which depends on jQuery.
Maybe we have a simple html page or other small file and we don't want to load jQuery the moment this file loads for whatever reason.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Seems like an odd thing to do, but you can construct a script tag for the jQuery library and add it to the DOM.

 
Shashank Agarwalg
Ranch Hand
Posts: 110
Android Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey by searching on internet i saw this example can you explain it

step - 1

 
Shashank Agarwalg
Ranch Hand
Posts: 110
Android Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
step - 2

 
Shashank Agarwalg
Ranch Hand
Posts: 110
Android Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
step - 3


 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Next time, single post--people stuffing the ballot box in an attempt to win free stuff are frowned upon.

The code does what Bear told you you could do.
 
Shashank Agarwalg
Ranch Hand
Posts: 110
Android Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey david that's not way to win free stuff. i wants to ask the solution of my query. If you thinks that your welcome. I am an beginer not expert i saw this code on internet and not understand in detail i understand only that it is calling jquery code from the page but what is it doing in step 3.
 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David means you can (and you should) post your code in one single post, not in three different posts.
 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Google also host the jQuery libraries. While it doesn't tackle the exact problem asked in the OP, it does two things,

1. Saves you the hosting and bandwidth.
2. Saves your end user a download of the library, if its already there from any other site they have visited (and uses Google as Host)

I guess the scenario in which the OP becomes useful is case #1 (is just a guess, what else is Dynamic loading of the library useful for if not to save some bandwidth?)
 
Shashank Agarwalg
Ranch Hand
Posts: 110
Android Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@john todd ok... i will remember next time. i post it in diffrent posts cause i wants to increase readability.

@sam yup i also thinks so it makes code faster to load andsaves time and save bandwith.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Shashank Agarwalg wrote:@john todd ok... i will remember next time. i post it in diffrent posts cause i wants to increase readability.


It's actually less readable, though--too much vertical and cognitive disconnect.
 
Shashank Agarwalg
Ranch Hand
Posts: 110
Android Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok... David i ill remember next time sorry for misbehevoour . actualy i am new to javaranch i wll remember thease things next time.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem :) (Although you're not *that* new, nearly a half year now!)
 
reply
    Bookmark Topic Watch Topic
  • New Topic