how to set cursor style to pointer for links without hrefs

JavascriptHtmlCssHyperlinkMouse Cursor

Javascript Problem Overview


I have a lot of <a> html tags without the href attribute for making onclick javascript calls. These links do not have a pointer style of cursor. They have text style cursor.

How can I set the cursor style to pointer for links without using the href attribute?

I know I can add href="#". I have this in a lot of places in the html document, and would like to know how to make cursor style pointer for links without using the href attribute.

Javascript Solutions


Solution 1 - Javascript

in your css file add this....

a:hover {
 cursor:pointer;
}

if you don't have a css file, add this to the HEAD of your HTML page

<style type="text/css">
 a:hover {
  cursor:pointer;
 }
</style>

also you can use the href="" attribute by returning false at the end of your javascript.

<a href="" onclick="doSomething(); return false;">a link</a>

this is good for many reasons. SEO or if people don't have javascript, the href="" will work. e.g.

<a href="nojavascriptpage.html" onclick="doSomething(); return false;">a link</a>

@see http://www.alistapart.com/articles/behavioralseparation

Edit: Worth noting @BalusC's answer where he mentions :hover is not necessary for the OP's use case. Although other style can be add with the :hover selector.

Solution 2 - Javascript

> style="cursor: pointer;"

Solution 3 - Javascript

This is how change the cursor from an arrow to a hand when you hover over a given object (myObject).

myObject.style.cursor = 'pointer';

Solution 4 - Javascript

Use CSS cursor: pointer if I remember correctly.

Either in your CSS file:

.link_cursor
{
    cursor: pointer;
}

Then just add the following HTML to any elements you want to have the link cursor: class="link_cursor" (the preferred method.)

Or use inline CSS:

<a style="cursor: pointer;">

Solution 5 - Javascript

Give them all a common class (for instance link). Then add in css-file:

.link { cursor: pointer; }

Or as @mxmissile suggested, do it inline with style="cursor: pointer;"

Solution 6 - Javascript

create a class with the following CSS and add it to your tags with onclick events:

cursor:pointer;

Solution 7 - Javascript

This worked for me:

<a onClick={this.openPopupbox} style={{cursor: 'pointer'}}>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkevinView Question on Stackoverflow
Solution 1 - JavascriptRossView Answer on Stackoverflow
Solution 2 - JavascriptmxmissileView Answer on Stackoverflow
Solution 3 - JavascriptLouView Answer on Stackoverflow
Solution 4 - JavascriptAndy ShellamView Answer on Stackoverflow
Solution 5 - JavascriptAlxandrView Answer on Stackoverflow
Solution 6 - JavascriptDanView Answer on Stackoverflow
Solution 7 - JavascriptBabaRickView Answer on Stackoverflow