/    Sign up×
Community /Pin to ProfileBookmark

attachEvent/addEventListener and setTimeout

hi, i have this code that binds onclick to the submit button and change the color, how can i use [B]setTimeout[/B] to chane to the default color after some time?

[CODE]var els = document.getElementsByTagName(‘input’);
for (i = 0; i < els.length; i++) {
var el = els[i];
if (el.type == “submit”) {
if (el.addEventListener) {
el.addEventListener(“click”, changeBG, false);
} else if (el.attachEvent) {
el.attachEvent(“onclick”, changeBG);
}
}
}

function changeBG() {
var ev = (event) ? event: event;
if (ev.srcElement) {
ev.srcElement.style.backgroundColor = ‘red’;
} else {
ev.target.style.backgroundColor = ‘red’;
}
}[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@web_bertJul 25.2009 — [CODE]
function changeBG(e) {
var ev = (e) ? e: window.event,
elem;
if (ev.srcElement) {
elem = ev.srcElement;
} else {
elem = ev.target;
}

elem.style.backgroundColor = 'red';

window.setTimeout(function(){
elem.style.backgroundColor = 'blue';
},1000);
}

[/CODE]
Copy linkTweet thisAlerts:
@eben0authorJul 25.2009 — thx a lot, that what i was needed
×

Success!

Help @eben0 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.22,
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,
)...