/    Sign up×
Community /Pin to ProfileBookmark

2 onclicks in one line?

I know I’m full of questions today but hopefully this is the last one….I have where something can have the background color changed with the onclick event and when you double click it changes back to white – my question is can I have it so I can have 2 onclicks in one line so the user doesn’t have to doubleclick? Here is my current line…

<tr onclick=”this.style.backgroundColor=’#D5E6F1′” ondblclick=”this.style.backgroundColor=’#ffffff'”>

so in a nutshell I want to not have the ondblclick and just have one a single onclick to toggle between the color changes.

Thanks in advance

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@balloonbuffoonMar 30.2006 — Try this:

<tr onclick="this.style.backgroundColor=(this.style.backgroundColor=='#D5E6F1') ? '#FFFFFF' : '#D5E6F1'">

--Steve
Copy linkTweet thisAlerts:
@ClasservauthorMar 30.2006 — I tried it and it only lets me click once to change the color to blue but doesn't do anything when you click again...stays blue. I've been working on so many scripts today I feel like I'm going batty...any other suggestions?

I'll keep fiddling with the code you suggested to see if I can get it to work in the meantime

Amy
Copy linkTweet thisAlerts:
@FangMar 30.2006 — The method does not work as IE and FF return the color code in a different format ( '#d5e6f1' and 'rgb(213, 230, 241)' )

Swap class:&lt;tr onclick="this.className=(this.className=='bgBlue') ? 'bgWhite' : 'bgBlue';"&gt;
Copy linkTweet thisAlerts:
@ClasservauthorMar 30.2006 — It works!!!! I'm so happy that I have one item off of my headache list. Thank you so much!!!

-Amy
×

Success!

Help @Classerv 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...