OK, so this sounds simple, using jquery's 'click' function.
The thing is I want the ORIGINAL color of the link NOT its hovered color - e.g. if the link is green with a hover state of orange, I wat to grab the GREEN color.
I've tried as best as I can and shown it in a fiddle
Anyone got any ideas?
EDIT: apologies, but as a number of eagle eyes have spotted (thanks to them for pointing it out) green is actually "rgb(0, 128, 0)", NOT rgb(0, 255, 0) as shown in my original fiddle.
To change the color of hyperlink text, click Hyperlink, and then click More Colors. To change the color of the followed hyperlink text, click Followed Hyperlink, and then click More Colors.
To change the color of links in HTML, use the CSS property color. Use it with the style attribute. The style attribute specifies an inline style for an element. Use the style attribute with the CSS property color to change the link color.
HTML body tag example TEXT = The color of text. LINK = The color of links. VLINK = Visited link color. ALINK = Color of the active link or the color the link changes to when clicked.
So, just right-click on the hyperlink and from the context menu select "Edit Hyperlink". It brings up the edit dialog box. Click on "OK". The hyperlink is returned to it's original blue state.
Store it in jQuery's data
object:
$('a').each(function() {
$(this).data('color', $(this).css('color') );
})
.click(function() {
alert( $(this).data('color') );
});
Here's your fiddle: http://jsfiddle.net/sVDYe/4/
For better performance, I'd use the static methods in the loop. They're much faster:
$('a').each(function() {
$.data(this, 'color', $.css(this, 'color') );
});
Here's the fiddle: http://jsfiddle.net/sVDYe/13/
Try like this
http://jsfiddle.net/dadviegas/hfHBh/
Try below approach..
DEMO: http://jsfiddle.net/sVDYe/33/
$("a").click(function(e) {
e.preventDefault();
var tmpLink =$(this).clone();
tmpLink.appendTo($(this).parent());
var acolor = tmpLink.css("color");
tmpLink.remove();
if (acolor == 'rgb(255, 165, 0)') {
alert('wrong color - its ORANGE =' + acolor);
} else if (acolor == 'rgb(0, 128, 0)') {
alert('CORRECT color - its GREEN =' + acolor);
}
});
As pimvdb pointed out.. Green is RGB(0,128,0)
You can handle the color change using Jquery instead of css and store it:
http://jsfiddle.net/sVDYe/20/
var hoverColor;
$("a").hover(function () {
hoverColor = $(this).css("color");
$(this).css("color", 'orange');
}, function () {
$(this).css("color", 'green');
});
$("a").click(function (e) {
e.preventDefault();
var acolor = hoverColor;
if (acolor == 'rgb(255, 165, 0)') {
alert('wrong color - its ORANGE =' + acolor);
} else if (acolor == 'rgb(0, 128, 0)') {
alert('CORRECT color - its GREEN =' + acolor);
}
});
Also green is
rgb(0, 128, 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With