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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:00:35+00:00 2026-06-09T16:00:35+00:00

I have the following jQuery source (modalConnect()) for loading a form and presenting it

  • 0

I have the following jQuery source (modalConnect()) for loading a form and presenting it via a boostrap modal. It basically prevents the default behavior of an href tag and instead submits an ajax get call. This works fine.

Now I have to add another .js script tag to the dom which I receive from the server. This also works for the first click, for each succeeding click the method is executed the number of times it has been already executed + 1. Which is very strange.

So for the first click I receive the following in the console:

function executed Additional JS executed

which is fine.

For the second click (on the same or another – makes no difference) I receive the following:

function executed Additional JS executed

function executed Additional JS executed

Having now printed the text in total three times in the console, whereas I would only expect having printed it two times.

<script type="text/javascript">
    function modalConnect()
        {
            $(".editItem").click(function(ev) { // for each edit item <a>
                ev.preventDefault(); // prevent navigation
                var url = ($(this)[0].href); //get the href from <a>
                $.get(url, function(results){
                  var itemForm = $("#ajax_form_modal_result", results);
                  console.log("function executed");
                  //update the dom with the received results
                  $('#itemFormModal').html(itemForm);
                  //add a new js script to the document. Repeated method calling effect only occurs if I add the following two lines
                  scriptText = "console.log('Additional JS executed')";
                  appendScriptTag(scriptText);
                  //show a bootstrap modal with the loaded form
                  $("#itemFormModal").modal('show');
                }, "html");
                return false; // prevent the click propagation
            })
        }
</script>

asdf

 <script type="text/javascript">
    function appendScriptTag(scriptText)
    {
        //create a script tag and append it to the dom
        var script = document.createElement( 'script' );
        script.type = 'text/javascript';
        script.text  = scriptText;
        //the following lines seem to have no effect.
        //the "method called more often" effect is not influenced by these lines
        document.body.appendChild(script);
        document.body.removeChild(document.body.lastChild);
        delete UnusedReferencedObjects; // replace UnusedReferencedObject with any object you created in the script you load.
    }

</script>

In addition I would be glad if someone could explain me how to properly remove the last js script tag which I added with appendScriptTag(). I think I end up with multiple js included, which is actually bad.

Not sure whether it is correct as I did it there, I followed the explanation from Hendra Uzia from this post.

  • 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-06-09T16:00:37+00:00Added an answer on June 9, 2026 at 4:00 pm

    Once a script is parsed and loaded, removing a script tag will not remove the script. So that’s why those lines have no effect.

    If you call modalConnect() multiple times throughout your code, the event listener on the button will also get duplicated, so that one click will cause 5 event listeners to be fired, resulting in 5 messages. That might be it…

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

Sidebar

Related Questions

I have started using leaflet as an open source map, http://leaflet.cloudmade.com/ The following jQuery
I am new to JQuery and I have the following issue: Source file: function
I have the following jquery Autocomplete form that pulls data in from a local
i have the following jQuery code. $(function() { $('.clickme').click(function() { $('.totalthing').slideToggle('slow','easeInOutQuart', function() { //
I have the following jquery script: $(function(){ $('#top-menu').on('click', 'a.change-menu', function(e){ e.preventDefault() $(#menu-change-div).load($(this).attr(href)); }); });
I have the following jquery code: $(document).ready(function() { $(body[class*=page-calendar-practices] #content-header h1#title).after(<div id='athletics_practice-schedule'><div id='inner-title'><a href='www.example.com'
I have the following jquery function that submits to an iframe. The message sent
I have the following jquery code which doesn't work quite right when trying to
I have the following jQuery code: $(body.page-calendar-practices-2012-05 #content-header h1#title) which works fine. I can
I have the following jQuery $.ajax({ type: GET, url: http://f.cl.ly/items/0i1V1L1k2F440L1m2Y0G/pointdata.xml, dataType: xml, success: parseXml

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.