PDA

View Full Version : Javascript wanted



paldo
11-16-2012, 06:25 PM
I'm looking for a Javascript that makes the following: I have a list of questions with three answers each. I would like to have the following behaviour: on rollover the correct answer should change to green color. Somebody can gives me a good hint?

Example:

Question 1: how much is 2+3?
a) the correct answer is 6
b) the correct answer is 5 On rollover to the question "b) the correct answer is 5" should change to green
c) the correct answer is 4

Beverleyh
11-16-2012, 10:22 PM
You can do this with the pseudo class :hover in CSS http://www.tizag.com/cssT/pclass.php

Please try to use a more description title for your post in future. Just saying 'JavaScript wanted' isn't a very accurate indicator if what your query is about and many people will choose to ignore it.

bernie1227
11-16-2012, 10:30 PM
Take a look here (http://www.dhtmlgoodies.com/tutorials/javascript-rollovers/#) under css styling for mootools.

paldo
11-18-2012, 09:33 PM
You can do this with the pseudo class :hover in CSS http://www.tizag.com/cssT/pclass.php

The suggestion that you mention changes the color of the question, not of one of the answer. I thing I have to develop a Javascript with getElementById

Beverleyh
11-18-2012, 09:45 PM
It (hover pseudo class) will effect whatever you target, but you need to define that in your CSS. Target the correct answer and not the question - wrap a span around it with a class, and target that in your CSS. You'll then be able to reuse the class on all the other corrects answers.

Beverleyh
11-18-2012, 09:50 PM
If you need more specific help, please post a link to your page

djr33
11-18-2012, 10:18 PM
Two things to add:
1. The hover method works in all browsers except earlier versions of Internet Explorer, in which it works only for <a> tags (links). Can someone confirm for me that it works in the latest versions of IE such as IE 8 and 9? I think so, but I'm not 100% sure on that.

2. Why do you want to give away the answer like this? I'm just checking to be sure this is the right way to approach it. I can imagine this might be a method of stopping bots from accessing the site (they can't read/understand well enough to do the math) as a sort of CAPTCHA. But if you include some kind of indication in the code (eg, a special CSS property), the bots will learn to figure that out, so it's actually problematic to do it that way.
If this is for unrelated reasons, it's probably fine. But I thought I'd check in on that.

Beverleyh
11-18-2012, 11:03 PM
Yes, IE7, 8 and 9 play nicely with :hover on all elements :)

djr33
11-18-2012, 11:17 PM
Ah, so it's just IE6 and below. Good to know. Those browsers can be more or less safely ignored at this point. Thanks.