Javascript – how to make div click-able



For div like above,when mouse on,it should become cursor:pointer,and when clicked,fire a

javascript function,how to do that job?

EDIT: and how to change the background color of div when mouse is on?

EDIT AGAIN:how to make the first span's width=120px?Seems not working in firefox

Best Solution

Give it an ID like "something", then:

var something = document.getElementById('something'); = 'pointer';
something.onclick = function() {
    // do something...

Changing the background color (as per your updated question):

something.onmouseover = function() { = 'red';
something.onmouseout = function() { = '';