I am trying to add a standard style to all javascript scripted hyperlinks in my webapps. Replacing the standard solid line with a dotted line. This can be achieved with CSS however there is a major drawback to that, the border color doesn't match the link color. I figured since the links are using JS anyways, why not do it with JS. Here is what I'm trying to do in jQuery.
$(function(){
$('a.scripted').css({
'text-decoration': 'none',
'border-bottom': '1px dotted',
'border-color': $(this).css('color'),
});
});
However, this doesn't work. $(this) doesn't refer to the selected element and that makes sense. My question is, how can I do this? I tried wrapping it like this:
$(function(){
$('a.scripted').ready(function(){
$(this).css({
'text-decoration': 'none',
'border-bottom': '1px dotted',
'border-color': $(this).css('color'),
});
});
});
This also did not work. Advice?
EDIT
This code works but not for visited links. I know about the jQuery selector :visited but how do I use that in this context?
$(function(){
$('a.scripted').each(function(){
var $this = $(this);
$this.css({
'text-decoration': 'none',
'border-bottom': '2px dotted',
'border-color': $this.css('color'),
});
$this.hover(
function()
{
$this.css({
'text-decoration': 'none',
'border-bottom': '1px dotted',
'border-color': $this.css('color'),
});
},
function()
{
$this.css({
'text-decoration': 'none',
'border-bottom': '1px dotted',
'border-color': $this.css('color'),
});
}
);
$this.click(function(){
$this.css({
'text-decoration': 'none',
'border-bottom': '1px dotted',
'border-color': $this.css('color'),
});
});
});
});