[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 838
  • Last Modified:

Want the hyperlink pointer finger to appear on anchor text without the href attribute.

I have anchor text that calls JavaScript when clicked.  Because the anchor lacks an href attribute, the anchor text doesn't show the characteristic hyperlink behavior (underlined text, and the pointer finger when the cursor is over the text).  I don't need the underline, but I would like to see the pointer finger.  How do I accomplish this?
0
jdana
Asked:
jdana
  • 2
  • 2
2 Solutions
 
Tomarse111Commented:
add style="cursor: pointer;" to your anchor tag styles :)
0
 
Michel PlungjanIT ExpertCommented:
Why not add the href???
<a href="#"
onClick="someFunction(); return false">Click</a>

is much more compatible and gives you the finger for free ;)
0
 
Tomarse111Commented:
if your going to add the href then shouldn't you add something along the lines of:

<a href="javascript:void(0)" onclick="someFunction();">

instead of the #? This would get around the the whole page bouncing to the top of the window scenario.

:-)
0
 
Michel PlungjanIT ExpertCommented:
No.

The return false on the onClick will stop that and the # only loaded if JS is turned off. IF js is turned off or not available, then javascript:void(0) will give a nasty http error


the BETTER solutions are


<script>
document.write('<a href="#" onClick="someFunction(); return false">Click</a>')
</script>
 
or 
 
<a href="please_turn_on_javascript_for_this_link_to_work.html"
onClick="someFunction(); return false">Click</a>

Open in new window

0
 
jdanaAuthor Commented:
style="cursor: pointer;" is perfect.  Thanks.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now