0

Hi I wrote a little script where every time state 1 is triggered the cursor changes to a pointer, and when state 2 is triggered it changes to a crosshair. Both states get triggered correctly and everything runs fine, except every time I am in state 1 only one of the divs which I want the cursor to change for show the right cursor. In state 2 everthing works like it should.

HTML

<div id='first'></div>
<div id='second'></div>

JS

function state1 (){
$('#first').css({'cursor':'pointer'});
$('#second').css({'cursor':'pointer'});
};

function state2 (){
$('#first').css({'cursor':'crosshair'});
$('#second').css({'cursor':'crosshair'});
};
4
  • Show the full CSS which is set besides what you set programmatically. Also, when you inspect your divs using runtime DOM inspection tools, can you see the styles being set?
    – nikc.org
    Jan 3, 2012 at 12:42
  • 3
    I would combine your two lines, e.g. $('#first, #second').css({'cursor':'pointer'});. This will improve your code's efficiency.
    – jabclab
    Jan 3, 2012 at 12:43
  • 2
    ...and as a second hint, you can just comma separate your selectors to match both in one go. I.e. $('#first, #second') to avoid repeating the same code twice.
    – nikc.org
    Jan 3, 2012 at 12:43
  • The code as given works fine jsfiddle.net/VkSAM marking as unanswerable
    – Esailija
    Jan 3, 2012 at 12:46

1 Answer 1

0

You don't execute function state1 properly in the code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.