Share this page 

Execute a javascript function by clicking on textTag(s): HTML/CSS


<script>
  function a() {
    alert("Hello")
    }
</script>
<a onClick="a();" style="cursor: pointer; cursor: hand;">*click here*</a>
Try it here : *click here*

NOTE : The style "cursor: pointer" works in Mozilla and Netscape 6+, IE6/Win, and IE5.x/Mac, but not IE5.x/Win where the "cursor: pointer" must be used. IE6/Win and IE5.x/Mac accept both the "pointer" and "hand"! That's why we are using "cursor: pointer; cursor: hand;". Do not reverse those two values! Written this way, NS6+ will see the first value and ignore the second, so you get pointer. In IE5.x/Win, it sees both and uses the second, so you get hand. If you reverse the values, then Netscape 6+ will be okay, but IE5.x/Win will see both and try to use the second. That won't get you the little hand-pointer icon in IE5.x/Win.

using SPAN

<span id="SpecialSpan"
      onmouseover="this.style.cursor='pointer'"
      onmouseout="this.style.cursor='default'"
      onclick="a()";>
      *click here*
</span>
Try it here : *click here*

The possible values for the cursor are

hand  (IE)
pointer (N)
auto (N6)
crosshair
default (arrow)
move
n|ne|e|se|s|sw|w|nw-resize
text (I-bar)(N6)
wait (hour glass)(N6)
help (arrow with"?")