5

i got a css rule like this:

#imgwrapper {display: block;position: relative;width:auto;height:auto;}

so i got a hyperlink that when it's clicked, it should add a css rule to #imgwrapper like this:

#imgtarget, #imgwrapper img {cursor:crosshair;}

how should i do it??

i tried jquery .css() api but it aint working..

4
  • Can you post the code you tried that used .css()? Commented May 1, 2011 at 6:36
  • Please post an example of the code you have that isn't working. Commented May 1, 2011 at 6:36
  • did you try below code , is it working... Commented May 1, 2011 at 6:44
  • hi everyone, the reply from David Fells works.. earlier i did it wrongly by doing it this way: $('#imgtarget').css('cursor:crosshair'); Commented May 1, 2011 at 6:55

2 Answers 2

9

See the $.css() function

$('a.whatever').click(function() {
  $('#imgtarget').css('cursor' , 'crosshair');
  $('#imgwrapper img').css('cursor', 'crosshair');
});
Sign up to request clarification or add additional context in comments.

2 Comments

hey david, your solution works.. but now wat if i wanna remove these css properties??
hey david, i found the solution. sorry my bad.. what i did is to set the value to ''.. so ie: $('#imgtarget').css('cursor' , ''); $('#imgwrapper img').css('cursor', '');
2

the following code should work.

$('#imgwrapper').css('cursor','crosshair')

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.