/    Sign up×
Community /Pin to ProfileBookmark

Hey, i have this code, however i want it to have more support, i was thingking about using if (document.getElememtById) but i have not been sucessful.
Thanks for your help.

[CODE]
function showthis(){
setTimeout(‘showthis2()’,6000);
}
function showthis2() {
div1.innerHTML=div2.innerHTML
}
[/CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@toicontienApr 26.2007 — You'll have to explain more about what you're doing. You're using two variables, div1 and div2, but how are those variables being declared? You really should write the showThis function like this:

function showthis(){
setTimeout(showthis2,6000);
}

The setTimeout function takes either a string that will be evaluated as JavaScript, or it takes a function object as its first argument. Since you've declared a function, by doing [B]function showThis2() { ... }[/B], you've actually created another object called "showThis2" that you can pass to other functions.

The screwy thing with JavaScript is that everything is an object. Objects are objects. Functions are objects. String variables are objects. Arrays are objects. You can pass them around to other functions using the name you gave them.

The advantage of passing the setTimeout function showThis2 instead of "showThis2()" is the latter needs to be interpretted as javascript. Just passing showThis2 allows the setTimeout function to immediately execute the function passed, instead of interpreting that string as JavaScript and then executing the showThis2() function.
Copy linkTweet thisAlerts:
@TaboauthorApr 27.2007 — I want:

User clicks a link, when it clicks there is a delay setTimeout('whatever',6000);
then the inner HTML of DIV1 is set to be the same as DIV2

The code i posted above does this, but without support for browsers other than IE
Copy linkTweet thisAlerts:
@toicontienMay 01.2007 — There must be some code missing. The code you posted in your first post should work cross-browser as long as div1 and div2 are global variables which reference an HTML node.

Can you post all of the JavaScript on that page? We probably need to see the HTML too. There might be a markup error at play here too.
×

Success!

Help @Tabo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...