Add css rule using jquery

I got a css rule:

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

so I got a hyperlink which, when it clicked, should add a css rule for #imgwrapper as follows:

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

How can I do it?

I tried jquery.css () api, but it does not work.

+5
source share
2 answers

See the function $. css ()

 $('a.whatever').click(function() { $('#imgtarget').css('cursor' , 'crosshair'); $('#imgwrapper img').css('cursor', 'crosshair'); }); 
+9
source

The following code should work.

 $('#imgwrapper').css('cursor','crosshair') 
+2
source

All Articles