I need load content of div, 2 sec after click button. Content is other html file. When i use
setTimeout($(".frame").load(this.href),5000);
div load content of file instantly. HELP
$(document).ready(function(){
$(".test").click(function(event) {
setTimeout($(".frame").load(this.href),5000) ;
});
});
When you say
setTimeout($(".frame").load(this.href),5000);
You are running $(".frame").load(this.href)
, and passing the result of that expression to setTimeout.
You should put it inside an anonymous function instead, which involves caching the this variable (as pointed out by @hindmost):
var self = this;
setTimeout(function() {
$(".frame").load(self.href);
},5000) ;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.