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 7043611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:18:39+00:00 2026-05-28T02:18:39+00:00

i want to add a .js file after a link has been clicked. The

  • 0

i want to add a .js file after a link has been clicked.
The .js file is a script, that has no function to call directly, but the file has to be inserted in the body part of the site.

Another solution would be, if the file is called at page load and if the click event of the link is called, then remove the .js file.

I’ve tried something like this, but nothing happens:

$(".myLink").click(function(){
    $.getScript("myJavascriptFile.js");
});

and also here:

$(".myLink").click(function(){
var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = "app_javascript/dragscroll.js";
        $(".myDiv").append(script); // or  $("body").append(script);
});
  • 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-28T02:18:40+00:00Added an answer on May 28, 2026 at 2:18 am

    Well, actually, “nothing happens” sounds most probably too loud.
    getScript is by all means asynchronous, so you should provide any code, which relies on using this script in load handler, which is actually, the second param.

    $.getScript('here_comes_the_script.js', function(){...//here comes the code})

    You can use some wrapping to make thing more flexible – by passing events to load handler, something like this:

    getScriptDetectable = function(src) {
         getScript(src, function() {
          $(document).trigger("new_script", {src: src})
         });
    }
    

    But this, of course, doesn’t free you from considering the fact that this code is asynchronous.

    And about removing script. There is actually no general way to make browser “unsee” the code.

    You can try do something like:

    var src = document.querySelector('script');
    src.parentNode.removeChild(src);
    

    but all code in this file which has been evaluated already is evaluated, so there is no much sense in this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add a link to a PDF file but instead of printing
I want to add dll file into my project. But i don't know where
Next to file menu i want to add a search menu that will have
i want to add file(photo) to fileupload control in the c#(code behind) thanks
I want to add swf file created by pdf2swf in vaadin window, So I
I want to add an XML file, containing sensitive data, to my application. I
I want to add some more library and helpers file into Pyrocms which is
I want to add a external third party jar file in the inbuilt android
I want to add two columns to a file with ~10,000 columns. I want
I want to add a custom configuration section in my app.config file. Is there

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.