[jQuery] Re: Targeting pseudo classes with jQuery

2008-03-07 Thread TheOriginalH

Perfect gentlemen, thank you very much :)


On Mar 7, 3:32 am, Hamish Campbell <[EMAIL PROTECTED]> wrote:
> Rather than setting CSS attributes directly, use classes. Eg, with
> hover:
>
> $('.someElements').click(function() {
>$('.someElements').removeClass('aSelected');
>$(this).addClass('aSelected');
>
> }
>
> $('.someElements').hover(
> function(){
> $(this).addClass('aHover') },
> function() {
> $(this).removeClass('aHover');
> }
> );
>
> This should solve your problem.
>
> On Mar 7, 10:57 am, TheOriginalH <[EMAIL PROTECTED]> wrote:
>
> > I have a menu which is working nicely. When an item is clicked, I'm
> > using jQuery to change the CSS color to indicate it is current. To
> > keep things neat, I have also changed the color of all similar items
> > back to the default (otherwise ALL items would be highlighted as you
> > went through the menu.
>
> > Unfortunately this has the side effect of killing the natural css
> > hover pseudo class :(
>
> > I've messed with the .hover function, but the implementation I've used
> > then kills the coloring on click (as when you mouse away from hover,
> > it returns to the default).
>
> > Anyone come across this and know how to fix it?
>
> > TIA,
>
> > H


[jQuery] Re: Targeting pseudo classes with jQuery

2008-03-07 Thread Hamish Campbell

Rather than setting CSS attributes directly, use classes. Eg, with
hover:

$('.someElements').click(function() {
   $('.someElements').removeClass('aSelected');
   $(this).addClass('aSelected');
}

$('.someElements').hover(
function(){
$(this).addClass('aHover') },
function() {
$(this).removeClass('aHover');
}
);

This should solve your problem.

On Mar 7, 10:57 am, TheOriginalH <[EMAIL PROTECTED]> wrote:
> I have a menu which is working nicely. When an item is clicked, I'm
> using jQuery to change the CSS color to indicate it is current. To
> keep things neat, I have also changed the color of all similar items
> back to the default (otherwise ALL items would be highlighted as you
> went through the menu.
>
> Unfortunately this has the side effect of killing the natural css
> hover pseudo class :(
>
> I've messed with the .hover function, but the implementation I've used
> then kills the coloring on click (as when you mouse away from hover,
> it returns to the default).
>
> Anyone come across this and know how to fix it?
>
> TIA,
>
> H


[jQuery] Re: Targeting pseudo classes with jQuery

2008-03-07 Thread Richard D. Worth
On Thu, Mar 6, 2008 at 4:57 PM, TheOriginalH <[EMAIL PROTECTED]> wrote:

>
> I have a menu which is working nicely. When an item is clicked, I'm
> using jQuery to change the CSS color to indicate it is current. To
> keep things neat, I have also changed the color of all similar items
> back to the default (otherwise ALL items would be highlighted as you
> went through the menu.


I think addClass() and removeClass() are a better fit here than css(). Ex:

menuItems.filter('.current').removeClass('current'); // or
oldItem.removeClass('current');
newItem.addClass('current');

Then you can simply have a different css rule for .current:hover, no?

- Richard

Richard D. Worth
http://rdworth.org/