Pages

Tuesday, November 18, 2008

How to change Mouse Pointer onmouseover using Javascript

JavaScript is a strong tool to work with Web Technology. You can complete all the tasks using JavaScript.

For ex. I have a task to chnage mouse pointer on mouse hover. The answer is too simple
use CSS.No, my css is not working due to some un avoidable reasons.

Finally I come to the conclusion i.e

Make a global.js contains

function set_mouse_pointer(obj)
{
obj.style.cursor='pointer';
}

Then implement this function like

Steps:
1) Put an HTML button of the page
2) Then on onmouseover event write code "onmouseover="set_mouse_pointer(this);"
3) View that page in browser.

You will see the effect.

This is a simple example of JavaScript. What you can do with JavaScript.

Please let me know if you have any major issues related to JavaScript

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Cross browser compatibility is a problem with this on IE uses hand, Firefox and others use pointer solution is use both 'pointer';'hand'

    Copy Paste this works with all browsers
    OnMouseOver="this.style.cursor='pointer';'hand'"

    ReplyDelete