<div><span>shanghai</span><span>male</span></div>
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
I suggest to use jQuery:
<div style="cursor: pointer;" onclick="theFunction()">
is the simplest thing that works.
Of course in the final solution you should separate the markup from styling (css) and behavior (javascript) - read on it on a list apart for good practices on not just solving this particular problem but in markup design in general.
add the onclick attribute
To get the cursor to change use css's cursor rule.
The selector uses an attribute selector which does not work in some versions of IE. If you want to support those versions, add a class to your div.
The simplest of them all:
Give it an ID like "something", then:
Changing the background color (as per your updated question):
If this div is a function I suggest use cursor:pointer in your style like style="cursor:pointer" and can use onclick function.
like this
but I suggest you use a JS framework like jquery or extjs