Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add css rule using jquery

Tags:

jquery

css

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..

like image 345
chrizonline Avatar asked May 01 '11 06:05

chrizonline


2 Answers

See the $.css() function

$('a.whatever').click(function() {
  $('#imgtarget').css('cursor' , 'crosshair');
  $('#imgwrapper img').css('cursor', 'crosshair');
});
like image 164
David Fells Avatar answered Nov 19 '22 20:11

David Fells


the following code should work.

$('#imgwrapper').css('cursor','crosshair')
like image 42
kobe Avatar answered Nov 19 '22 20:11

kobe