File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes How can i dynamically load the jQuery javascript library without using ajax Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How can i dynamically load the jQuery javascript library without using ajax" Watch "How can i dynamically load the jQuery javascript library without using ajax" New topic
Author

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

Shashank Agarwalg
Ranch Hand

Joined: Mar 03, 2010
Posts: 110

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.


Trying to win the world.....................
SCJP 6.0 , SCWCD/OCPJWCD 5, BlackBerry Developer
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Shashank Agarwalg
Ranch Hand

Joined: Mar 03, 2010
Posts: 110

can i call the perticuler jquery function in Html page at perticular moment.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Like at *what* "particular moment"? I mean, jQuery is just a library--you can call its methods whenever you want.
Shashank Agarwalg
Ranch Hand

Joined: Mar 03, 2010
Posts: 110

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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Mar 03, 2010
Posts: 110

Hey by searching on internet i saw this example can you explain it

step - 1

Shashank Agarwalg
Ranch Hand

Joined: Mar 03, 2010
Posts: 110

step - 2

Shashank Agarwalg
Ranch Hand

Joined: Mar 03, 2010
Posts: 110

step - 3


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Mar 03, 2010
Posts: 110

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.
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

David means you can (and you should) post your code in one single post, not in three different posts.
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 605

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?)


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Shashank Agarwalg
Ranch Hand

Joined: Mar 03, 2010
Posts: 110

@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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Mar 03, 2010
Posts: 110

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
Rancher

Joined: Sep 29, 2008
Posts: 12617

No problem :) (Although you're not *that* new, nearly a half year now!)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can i dynamically load the jQuery javascript library without using ajax