Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 743581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:52:51+00:00 2026-05-14T08:52:51+00:00

Disclaimer: JS novice I have a JS widget that depends on JQuery. The widget’s

  • 0

Disclaimer: JS novice

I have a JS widget that depends on JQuery. The widget’s going to be embedded in a 3rd party site but I figure out how to avoid declaring dependency on jquery on the widget-hosting page:

3rd party’s page:

<head>

<script
  type="text/javascript"
  src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>

<script
  type="text/javascript"
  src="http://mydomain/mywidget.js"></script>

</head>

mywidget.js

jQuery(document).ready(function() {
     //do stuff
});

I’d rather not include jquery.js in the 3d party page but express the dependency inside mywidget.js (so i can change this dependency or add/remove others w/o having to update the widget-hosting page)

I tried adding:

var script = document.createElement('script');
script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js';
script.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(script);

to the top of mywidget.js but that didn’t work – jquery.js did load on page load but “jQuery” was not recognized.

What did work was concatenating jquery.js and mywidget.js into a single .js file. But that seems kind of lame – is there no equivalent to?

import com.jquery.*;

thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T08:52:51+00:00Added an answer on May 14, 2026 at 8:52 am

    In your script, your widget code is immediately executed after the script element is appended, but it needs to wait until the script is also download and compiled! To achieve this, use this code:

    script.onload = function(){
    
        // ------ Your widget code here ------
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Disclaimer: absolute novice in Scala :( I have the following defined: def tryAndReport(body: Unit)
Disclaimer: I am new to python and django but have Drupal programming experience. I'm
Disclaimer: I have attempted to contact the developer about this plugin, but silence reigns.
Disclaimer: I am not going to say that I am the most experienced Java
Disclaimer: I have 10 years' experience programming, but 8 of which is in PHP
Disclaimer: I have no Twitter API experience nor have I used Twitter until today
(Disclaimer: I am a C# guy. I've just started learning Clojure.) I understand that
Disclaimer: I'm new to web development. I can't seem to figure out what is
Disclaimer : this is a strange issue that only happens in a Kindle Fire
Disclaimer: I'm new to unit testing and just getting my feet wet. That being

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.