meastwood
February 8th, 2010, 03:16 PM
Am using jquery.
I simply use load() to update the current page with content from another page. I then run a function to modify a few dom elements.
Everything works if I stick an alert("..") in the called function. When I remove the alert() the dom elements remain unchanged.
I've tried using setTimeout(called function, delay).
I've tried using a wrapper function to call the load() and dom modifying function separately - still requires an alert() in either function to work.
Because things work with alert() I think this is a timing issue - browser has yet to render the loaded dom elements before the second function is called.
function ajaxIt(tag_url) {
get_file(tag_url);
local_links();
}
function get_file(tag_url) {
var tag_and_url = tag_url.split(",");
$(tag_and_url[0]).load(tag_and_url[1]+' .contents');
//alert("done") will work
}
function local_links() {
// alert("called") will work
$('.local').click(function () {
var tgt = $(this).attr('href');
var off = $(tgt).offset();
var x = off.left;
var y = off.top - 190;
if ( x != 99 ) {
$(tgt).offset({ top:y, left: 99 }); }
$(tgt).scrollTo(1500); });
}
Either //alert() when uncommented will result in the desire result
I simply use load() to update the current page with content from another page. I then run a function to modify a few dom elements.
Everything works if I stick an alert("..") in the called function. When I remove the alert() the dom elements remain unchanged.
I've tried using setTimeout(called function, delay).
I've tried using a wrapper function to call the load() and dom modifying function separately - still requires an alert() in either function to work.
Because things work with alert() I think this is a timing issue - browser has yet to render the loaded dom elements before the second function is called.
function ajaxIt(tag_url) {
get_file(tag_url);
local_links();
}
function get_file(tag_url) {
var tag_and_url = tag_url.split(",");
$(tag_and_url[0]).load(tag_and_url[1]+' .contents');
//alert("done") will work
}
function local_links() {
// alert("called") will work
$('.local').click(function () {
var tgt = $(this).attr('href');
var off = $(tgt).offset();
var x = off.left;
var y = off.top - 190;
if ( x != 99 ) {
$(tgt).offset({ top:y, left: 99 }); }
$(tgt).scrollTo(1500); });
}
Either //alert() when uncommented will result in the desire result