// I am trying to apply an "onfocus="this.blur();"" so as to remove the dotted border lines around pics that are being clicked-on
// the effect should be applied to all thumb-nail links/a-tags within a div..
// sudo code (where I am):
$(".box a").focus( // so as to effect only a tags within divs of class=box | mousedown vs. onfocus vs. *** ?? | javascript/jquery... ???
function ()
{
var num = $(this).attr('id').replace('link_no', '');
alert("Link no. " + num + " was clicked on, but I would like an onfocus=\"this.blur();\" effect to work here instead of the alert...");
// sudo bits of code that I'm after:
// $('#link_no' + num).blur();
// $(this).blur();
// $(this).onfocus = function () { this.blur(); };
}
);
// the below works for me in firefox and ie also, but I would like it to effect only a tags within my div with class="box"
function blurAnchors2()
{
if (document.getElementsByTagName) {
var a = document.getElementsByTagName("a");
for (var i = 0; i < a.length; i++) {
a[i].onfocus = function () { this.blur(); };
}
}
}
views:
251answers:
3
A:
It's not recommended to blur. If all you're looking at doing is hiding the focus lines, use this instead:
a[i].onfocus = function () { this.hideFocus = true; };
This will work for all versions of IE. For other browsers (including IE8 in standards mode) you can set the outline CSS style to hide focus outlines:
a {
outline: none;
}
This would make your page much more keyboard friendly than blurring an element as it takes focus.
Andy E
2010-03-15 11:44:28
A:
I would suggest using only CSS to remove the border.
img, a:active{
outline: none;
}
Or is there a specific reason why JS must be used?
abloodywar
2010-03-15 11:49:08
CSS alone can't do this in IE6 and IE7. Also, `:focus` would be more appropriate than `:active` since the outline is used to mark the currently focused element.
Andy E
2010-03-15 11:51:31
But did he not want it removed only when clicked on?Using :active will still allow the user to see what has been focused, which would be more friendly for non-mouse users.
abloodywar
2010-03-15 11:53:57
@abloodywar: his question is asking about using `blur()` in the `onfocus` event, so it looks like he's trying to catch stop them on focus, not mouse clicks. The point of removing the outline is that you can apply a custom style on `:focus` instead.
Andy E
2010-03-15 11:57:11
+1
A:
Thanks guys - I have gone for the css(a:focus):
img, a:focus{ outline: none; }
It seems to be working right(tabbing is still working and the borders are gone when clicking) for me... in both ie and firefox. Will have to now retrofit some other links to use it...
Thanks again.
carpenter
2010-03-15 12:46:08