homepage Welcome to WebmasterWorld Guest from 54.166.100.8
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

    
Removing the dotted focus border inside a button
bsbarker




msg:4133416
 4:59 am on May 16, 2010 (gmt 0)

I'm using <input type='button' class='button' onclick='myFunction()' /> to call a function, and I'm using CSS to replace the standard button graphic with a round image. Is there a way to get rid of the dotted border that appears inside a button when you click it? Since my image is round, that dotted border sticks out on the "corners" and makes the image look a bit messy.

The border disappears when focus is removed from the button (aka onblur), as in clicking elsewhere or tabbing off of the button. So one idea I had was to automatically remove focus from the button when it is clicked:

i.e.
<input type='button' class='button' onclick='myFunction(); focusElsewhere' />

But I don't know how to do that. Does anyone else know? Or do you have other ideas how to accomplish what I'm trying to do here?

Let me know if you need me to post the CSS I'm using to replace the button graphic.

Thanks!

 

tedster




msg:4133423
 5:23 am on May 16, 2010 (gmt 0)

Try adding the attribute
hidefocus="true" to your input element. It used to work anyway.

Side note: it is usually not a good idea to obscure the focus event. Doing so sacrifices usability and accessibility for non-visual browsers. But it's your decision whether to make that trade-off.

bsbarker




msg:4133429
 6:35 am on May 16, 2010 (gmt 0)

Thanks, tedster, the hidefocus attribute worked.

However, taking non-visual browsers into consideration (which I've never done, so I wonder how compatible my site is anyway), can you think of a way to use the onclick attribute to move the focus to a different element instead of supressing the focus of my input element?

I suppose that would still make it inconvenient for a non-sighted user, though. Since the button is meant to be pushed multiple times, they would have to tab back to it each time. Just brainstorming here, mostly out of curiosity.

Do any alternative solutions come to mind?

tedster




msg:4133639
 6:27 pm on May 16, 2010 (gmt 0)

Nothing has ever come to mind or I would have shared it. The dotted line is a browser-specific affectation that has always been kind of ugly to my eyes, but I've finally quit worrying about it. Users of a browser that displays focus that way are used to it, I figure. So now I just let things go to default status.

Note that the "hidefocus" attribute is Microsoft-specific mark-up and it does not validate.

[edited by: tedster at 8:38 pm (utc) on May 16, 2010]

bsbarker




msg:4133671
 8:21 pm on May 16, 2010 (gmt 0)

Okay, thanks again for the input. I'll consider whether or not to use the hidefocus attribute, but either way it's good to know that it works at least.

kaled




msg:4133748
 12:37 am on May 17, 2010 (gmt 0)

Try this...

<input type="button" onclick="this.blur(); myFunction(); return true;" />

NOTE: Even if this appears to work, my recommendation would be to forget about this problem rather than use the code above because there may be compatibility issues on complex pages.

Kaled.

bsbarker




msg:4133763
 1:55 am on May 17, 2010 (gmt 0)

kaled, that works very well. It shows the focus border "onMouseDown" and removes it "onMouseUp", showing the user that their click did something but also preserving the appearance of the image. It also allows the user to tab to the button if desired.

This is a good alternative to the "hidefocus" attribute, but the problem remains that a user must tab back to the button each time they wish to push it. Still diciding if this is something I need to consider for my particular website. Both you and tedster are far more experienced than I am, so I do put weight in the fact that you both recommend against toying with the focus border at all.

One question on the possible compatibility issues you mentioned. If the code is not compatible in certain situations, will the code simply be ignored or might it break something?

kaled




msg:4133884
 9:35 am on May 17, 2010 (gmt 0)

When designing, it's easy to get caught up with unimportant details.

Compatibility issues could arise depending on how the blur() method is implemented. My understanding is that the next control in the tab-order is supposed to be focused - this is pretty silly - so my guess is that browser writers do something else. If blur() is implemented this way, then it really ought to be called focusNext() instead.

Kaled

bsbarker




msg:4134226
 8:21 pm on May 17, 2010 (gmt 0)

I agree, that would make more sense. Okay, well thanks again for your input.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved