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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:45:25+00:00 2026-05-31T12:45:25+00:00

right now , I use jQUery(document).ready to inject javascript into a div. All is

  • 0

right now , I use jQUery(document).ready to “inject” javascript into a div.

All is fine – but The problem is – that the same div is being refreshed via AJAX – and the JS in that case is not being “re-injected”..

(if someone is interested – the div is actually a “widget in wordpress “widgets admin” area)

My problem is that jQuery(document).ready obviously does not work (the DOM is already “ready”) and when I tried jQuery('#divname').ready – I also could not make it work.

I even tried .ajaxComplete() but to no avail …

I am not sure if it is a general method problem or a specific WP widgets problem..

EDIT I – for popular request : my script 🙂

//php wrapper function here ...

// .. php stuff.

    return "

    <script type='text/javascript'>
var map;
var markersArray = []; // to be used later to clea overlay array
jQuery(document).ready(function() {
    var lat = ". $lattxt . " ; // .. php variable.
    var lon = ". $lontxt . " ; // .. php variable.
    var marker;
    // ...continue boring google map code 
    };
    map = new google.maps.Map(jQuery('#DivName')[0], myOptions);
   // ...tinue boring google map code 

    function placeMarker(location) {
       ///...continue boring google map code 
        }
    }

});</script>
    <div id='DivName' style='height:200px; width:100%;' ></div><br />
    ";

what I am actually doing is creating a DIV and initiating google map.
The problem is when this “widget” (or “div”) is being “saved” via AJAX for options and refreshed – the Javascript is not working (it IS being injected in the code – but not “initiating..)

As I said before – this method is working just fine on the “first” go – but if the div is being refreshed – it is not working anymore even if the div is there and the javascript also there …

EDIT 1 :

I have found the following links which might or might not help anyone with similar problems :

a short explanation of the problem with a possible solution :
http://www.johngadbois.com/adding-your-own-callbacks-to-wordpress-ajax-requests/

Two related questions :

markItUp for WordPress widget

jQuery Functions need to run again after ajax is complete

That being said – I was not yet able to solve my specific problem. if i will I will post complete answer.

  • 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-31T12:45:26+00:00Added an answer on May 31, 2026 at 12:45 pm

    I believe you want DOM mutation events. These fire whenever the DOM changes.

    http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-eventgroupings-mutationevents

    Specifically, DOMSubtreeModified, however browser support is limited.

    There is a jQuery plugin that may help:

    https://github.com/jollytoad/jquery.mutation-events

    However, more detail about what you are actually trying to accomplish may help. There may be a simpler way to do what you want.

    Edit:

    If I understand now (and it is still not entirely clear), you are injecting this javascript into your div, but it is not running because the code is waiting for jQuery(document).ready().

    If this is the case, you should be able to either:

    1. Get rid of the jQuery(document).ready() wrapper, and your code will run as soon as it loads, but may cause problems on the initial load.

    2. Reformat your code so you can call your function after the AJAX load:

     

    var map;
    var markersArray = []; // to be used later to clea overlay array
    
    function doMap() {
        var lat = ". $lattxt . " ; // .. php variable.
        var lon = ". $lontxt . " ; // .. php variable.
        var marker;
        // ...continue boring google map code 
        };
        map = new google.maps.Map(jQuery('#DivName')[0], myOptions);
       // ...tinue boring google map code 
    
        function placeMarker(location) {
           ///...continue boring google map code 
            }
        }
    
    };
    
    jQuery(document).ready(function() {
        doMap();
    });
    
    </script>
    

    Then call doMap() after your reload. Of course, this is a guess again.

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

Sidebar

Related Questions

Right now i use iText to generate a pdf automatically. And my problem is
Background: I have a kubuntu laptop right now that I can't use wirelessly, i.e.
Right now we just use something like this stopWatch.Start(); try { method(); } finally
Right now I can use this URL to request a Google Static Maps image
Right now I have been trying to use Launchpad's API to write a small
Right now, I have two Eclipse projects - they both use Maven 2 for
Right now, my SVN repository is on my laptop's HDD (although I use a
So right now I'm bashing my head - at the moment we use an
I'm trying to use regular expression right now and I'm really confuse. I want
I have a working script like this: jQuery(document).ready(function(){ $('.video-thumb img').bind('mouseover',function(){ var new = $(this).attr('src').replace(/default.jpg/,'1.jpg');

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.