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 :
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.