473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

DOM Anchor Hover attribute

I posted a recent message regarding navigating a table using arrow
keys. I've got the code for the navigation working.

My table contains rows of links (anchors). I can get to a specific link
using the code for capturing a key. However, once I get to the link, I
can focus(), for example... but what I really want is to activate the
"hover" styles.

I can fake the hover effect using javascript, but how do I do this and
still allow the user to use the mouse to navigate the table???? I'm
getting more and more confused. I'm wondering if it's even worth it...

Here is a function where I loop through the table to get to the anchors
in the first column. Once I get the anchor, is there a way to activate
the hover effect???

function getRows()
{
var table = document.getElementById('myTable');

for ( var i = 0; i<table.rows.length ; i++ ) {
var myAnchor = table.rows[i].getElementsByTagName("a");
if ( myAnchor.length )
{
myAnchor[0].focus();
return;
}
}
}

Any help would be most appreciated... Thanks. D

Aug 28 '05 #1
2 4139
sk***@valley.net wrote :
I posted a recent message regarding navigating a table using arrow
keys. I've got the code for the navigation working.
Navigating through links can be easily achieved without CSS, without
javascript. Just tab through them. In Opera 7+, just use q and a keys.
Otherwise just use accesskey attribute accordingly. I insist to say that
no css and no javascript is needed for all this.

My table contains rows of links (anchors).
So far, this definitely sounds like table design to me.

I can get to a specific link using the code for capturing a key. However, once I get to the link, I
can focus(), for example... but what I really want is to activate the
"hover" styles.
then just code the :hover pseudo-class for links
<style type="text/css">
a:hover {background-color: silver; color: blue;}
a:hover:visited {background-color: silver; color: purple;}
</style>

I can fake the hover effect using javascript, but how do I do this and
still allow the user to use the mouse to navigate the table????
Impossible to answer you without knowing more about the page, code, etc.
An url would help.

I'm getting more and more confused. I'm wondering if it's even worth it...

No url. <shrug>
Here is a function where I loop through the table to get to the anchors
in the first column. Once I get the anchor, is there a way to activate
the hover effect???

Your question is not clear. Do you want to activate the link? or do you
want such link to have an hover effect? or a focus effect?
function getRows()
{
var table = document.getElementById('myTable');

for ( var i = 0; i<table.rows.length ; i++ ) {
var myAnchor = table.rows[i].getElementsByTagName("a");
if ( myAnchor.length )
{
myAnchor[0].focus();
return;
}
}
}

Also, I doubt your code is really needed if all the links in the page
are in that "myTable" table. Then, you'd only need to access the links
array.
Any help would be most appreciated... Thanks. D


Posting an url would help answer several questions. For instance, you
seem to make no difference between links and anchors.
Also, you want your design to work for which browser and browser versions?

Gérard
--
remove blah to email me
Aug 29 '05 #2
sk***@valley.net wrote:
I posted a recent message regarding navigating a table using arrow
keys. I've got the code for the navigation working.

My table contains rows of links (anchors). I can get to a specific link
using the code for capturing a key. However, once I get to the link, I
can focus(), for example... but what I really want is to activate the
"hover" styles.

I can fake the hover effect using javascript, but how do I do this and
still allow the user to use the mouse to navigate the table???? I'm
getting more and more confused. I'm wondering if it's even worth it...

Here is a function where I loop through the table to get to the anchors
in the first column. Once I get the anchor, is there a way to activate
the hover effect???
I think your only option is use script to remove all styles applied by
a:hover etc. and replace them with classes. Then when you give the link
focus, also change its class. When the focus moves on, restore the link
to the 'non-focused' class.

Using script to remove the styles in the first place means that users
without JavaScript will still see your behaviour when using a pointing
device.

I guess it's worth mentioning that you can navigate through links with
the tab key without any scripting - why not use that with the A's
onfocus/onblur event? The issue with using the arrow keys is that they
are used for other things already, like page scrolling and moving the
insertion point inside textarea elements.

Do you intend to disable those behaviours? When do the arrow keys move
the 'link focus' and when not? By the time you sort all that out,
you'll have a real mess I think.

Try the example below:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>Link focus</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=ISO-8859-1">

<style type="text/css">
..linkF {background-color: #eeeeff;}
..linkNF {background-color: #ffffff;}
</style>

<script type="text/JavaScript">

function hoverMe( el ){
while ( el.parentNode && 'tr' != el.nodeName.toLowerCase() ){
el = el.parentNode;
}
if ( el.className ) {
el.className = (el.className == 'linkF' )? 'linkNF':'linkF';
}
}

</script>

</head><body>

<table border="1">
<tr class="linkNF">
<td><a href="http://intranet/ictplanning"
onfocus="hoverMe(this);"
onblur="hoverMe(this);"ICT Planning</a></td> <td>Something about the link</td>
</tr><tr class="linkNF">
<td><a href="http://www-internal.qdot.qld.gov.au/"
onfocus="hoverMe(this);"
onblur="hoverMe(this);"QT</a></td>

<td>Something about the link</td>
</tr>
</table>

</body>
</html>
--
Rob
Aug 29 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: CJM | last post by:
Is it possible to achieve a hover effect for a non-anchor tag in CSS? I can use the following code, but it goes against the grain: <a href="" onclick="return false;">Label</a> Surely there...
1
by: Patrick | last post by:
I am trying to get "first-letter" to work inline withing an anchor. Actually I have not been able to get it to work within an <a> tag whether inline, linked, or embedded. Using IE6 service pack 1....
1
by: Frostillicus | last post by:
Does anyone know how to get around the problem IE seems to suffer from whereby an image within an anchor tag ignores the :hover pseudo element for the anchor in which it lives? Firefox is fine but...
3
by: DC | last post by:
Given: a { text-decoration:none; } a:hover { text-decoration:underline; }
16
by: Frances | last post by:
<a href="#1"> <a name="#1"> this link is not working in FF (works fine in IE..) would appreciate thoughts/suggestions.. thank you.. Frances
8
by: maya | last post by:
I have some links.. http://www.francesdelrio.com/linksCSS.html want it so when you hover over link ENTIRE DIV gets gray bg color (not just text (like link Three is now on this page..) but...
4
by: yawnmoth | last post by:
Say I wanted to make a link change colors when someone was hovering over it. Ordinarily, I could do that by doing something like... <style> a { color: whatever; } a:hover { color:whatever;
1
by: praveenb000 | last post by:
Hi every one, I designed a web page, having horizontal menu using UL and LI tags; I need to be set rollover effect for a menu items. whenever user hover on a menu item, the entire...
8
by: azjudd | last post by:
Thank you in advance for your help on this one. I'm using named anchor tags on a FAQ page with questions listed at the top and answers below; a standard jump-to feature. However, anytime an anchor...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.