[RESOLVED] How to execute function after div loads?
How to execute function after div loads
heres my function, if div exists return "true", now how to use chkObject('div') do loop until return true?
Code:
function chkObject (theVal)
{
if (document.getElementById(theVal) != null)
{
return true;
}
else
{
return false;
}
}
I found jquery code but does not work!
Code:
$("#div1").load(function() {
alert("The div has been loaded.");
});
div
HTML Code:
<html>
<head>
<title> </title>
<style>
#div1 {background-color : fffccc;width : 100;height : 100;}
</style>
</head>
<body>
<div id="div1" >
<p> my div1</p>
</div>
</body>
</html>
any help would be appreciated
best regards
One way to do it is to put the call to
Code:
function chkObject(elemId) {
return (document.getElementById(elemId))? true : false;
}
in a setInterval() and then put the setInterval() in window.onload to start it automatically when the page loads.
When chkObject(elemId) returns true, clear the setInterval() and then execute whatever javascript you need.
Last edited by tirna; 08-20-2010 at 08:37 PM .
hi tirna thanks a lot for your reply, i don't want to use window.onload is there any other way!
Another option is to put the setInterval() in a <script> block within the <body> or <head>
btw - just out of curiosity is the reason you don't want to use window.onload because this is for some kind of school project and you haven't covered window.onload yet?
Last edited by tirna; 08-20-2010 at 09:06 PM .
i don't want to use window.onload, Just because i don't want to wait for the entire document to load
ok, then all you have to do is put the setInterval() in a <script> block wherever you would like it to start in the <head> or <body>
@tirna Thank you very much. i really appreciate your help, its working
Code:
var int=setInterval('check()', 500);
function check()
{
if (chkObject('div')==true)
{
window.alert('true');
int=window.clearInterval(int)
}
else
{
document.write('<p>false </p>')
}
}
function chkObject(elemId)
{
return (document.getElementById(elemId))? true : false;
}
no problem - happy to help
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks