Just put the class in the selector instead of testing for it first: $("#portfolio #thumbs li.selected").css('opacity','0.5');
If the class doesn't exist, jQuery will do nothing (instead of throwing an "undefined" error or similar). On Tue, Jan 5, 2010 at 12:45 PM, Paul Collins <pauldcoll...@gmail.com> wrote: > Hi all > > I've been stuck on this for four hours, and I still can't solve it! > > I am trying to check if a list item has a class of selected, then is so > change the opacity to 0.5. Here is my code: > > if ($("#portfolio #thumbs ul li").hasClass(".selected")) { > $(this).css('opacity','0.5'); > } > > It seems that the "this" part isn't working, is it to do with putting it in > an event? > > Would appreciate any help > > >