admin管理员组文章数量:1425863
I'm trying to run a function on an object that is loaded into the DOM when the user clicks on the menu. Here is some part of my code:
$('#menu li a').click(function(){
var toLoad = $(this).attr('href');
//...
var $newItem = $('<li></li>').appendTo($(columns).first());
loadContent();
function loadContent() {
$newItem.load(toLoad, runScript());
}
function runScript() {
//see the code in IE9's debugger
alert($newItem.get(0).outerHTML);
obj.doWidget($newItem.get(0));
}
return false;
});
The problem is, when I click on the menu item, the alert
function in the above code, shows the code before loading: <li></li>
and not the loaded element from the object itself hence the script changes the old object and the new object overwrites its content. (like I've never ran the script). I assumed that the fallback function should implement return the loaded object. How can I get that object? Thanks.
I'm trying to run a function on an object that is loaded into the DOM when the user clicks on the menu. Here is some part of my code:
$('#menu li a').click(function(){
var toLoad = $(this).attr('href');
//...
var $newItem = $('<li></li>').appendTo($(columns).first());
loadContent();
function loadContent() {
$newItem.load(toLoad, runScript());
}
function runScript() {
//see the code in IE9's debugger
alert($newItem.get(0).outerHTML);
obj.doWidget($newItem.get(0));
}
return false;
});
The problem is, when I click on the menu item, the alert
function in the above code, shows the code before loading: <li></li>
and not the loaded element from the object itself hence the script changes the old object and the new object overwrites its content. (like I've never ran the script). I assumed that the fallback function should implement return the loaded object. How can I get that object? Thanks.
1 Answer
Reset to default 5Pass a reference to runScript
not the results of executing the function:
$newItem.load(toLoad, runScript);
本文标签: javascriptjQueryRun a function after load() is complete AND DOM is updatedStack Overflow
版权声明:本文标题:javascript - jQuery - Run a function after .load() is complete AND DOM is updated - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745447057a2658711.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论