Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing cursor with CSS in anchor tag

Status
Not open for further replies.

theniteowl

Programmer
May 24, 2005
1,975
US
Hi All,
I need to use an anchor tag without an HREF like this:
<a onclick="myfunction()">My text</a>

I cannot get CSS to change the mouse pointer when I hover over the anchor text.

Can this be done? Other than using javascript onmouseover?

Paranoid? ME?? WHO WANTS TO KNOW????
 
I know the commands but it does not seem to work with an anchor tag that does not contain an HREF.

It seems that the A css commands tie to the HREF rather than the A. Set one up that works fine WITH an HREF and then remove the HREF and it breaks completely. No more changes in color, font or anything else.


Paranoid? ME?? WHO WANTS TO KNOW????
 
I had not tried a span tag yet.
I had worked around it by including the href with no destination and using an onclick event with a return statement to prevent it trying to go anywhere.

I originally had a long anchor tag with mouse events to change the colors and change the pointer to a hand and back again but am trying to clean up my code using style sheets to control the look of it all and make it easier to support down the road.



Paranoid? ME?? WHO WANTS TO KNOW????
 
i usually use what you just described as the preferred method:

Code:
<a href="#" onclick="return false;">stuff</a>

but, as always, gotta think about the people that disable JS.

*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Sorry, didn't mean to imply you were a novice... I didn't read carefully enough. Anchor tags require an HREF property.

Thomas D. Greer
 
I reckon we tar all non-javascript users with the same brush... and point them to a page (rather than just a #):
Code:
<a href="require_javascript.html" onclick="myFunction();return false;">Test</a>
That way you can direct all non-javascript users to a plain HTML page that explains why you require javascript for the site/or to do the task you requested.

It's also a good opportunity for you to try and justify why you need javascript and can't do the task either server-side or without javascript altogether.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Here's a good way:
Code:
a:hover {
cursor: help;
}
..........
<a href="javascript:void(0);" onclick="this.blur();">Anchor content</a>
 
Hmm not quite correct tgeer
Anchor tags require an HREF property.
Anchor tags can be used as a target for a hyperlink.
Code:
<a name = "destination"></a> 
<a href = "#destination">Go to the Destination</a>
More correctly put, anchor tags used as hyperlinks require the HREF property.

Glen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top