jQuery: The Write Less, Do More JavaScript Library

Selectors

View: New views
3 Messages — Rating Filter:   Alert me  

Selectors

by manimal-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Here's what I'm trying to do. When I click on a tr i'd like it to hide
then re-style the table to alternate gray rows.

So on click I hide the tr then run this at the end of the animation/
hide

$('tr .myToggle').removeClass('gray');
$('tr .myToggle').not(':hidden').not(':even').addClass('gray');

I want to know if there is a better way of writing the second line:
$('tr .myToggle').not(':hidden').not(':even').addClass('gray');

I've tried:
$('tr .myToggle:not(':hidden'):odd').addClass('gray');//does not work

And some other variations on that. If i leave off the :not(':hidden')
i'll get all rows whether hidden or not, which means coloring odd or
even rows will not work, it won't look stripped.

Anyway does anyone know how to do this in the selector? Or could you
point me to some documentation on how to write selectors?

Thanks!

Re: Selectors

by jmatthews :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



The reference does not show the use of quotes like you have:
http://docs.jquery.com/Selectors/not#selector

Their example:   $("input:not(:checked) + span").css("background-
color", "yellow");

Yours re-written:  $('tr .myToggle:not(:hidden):odd').addClass
('gray');//hopefully works


On Nov 2, 3:31 pm, Manimal <scire...@...> wrote:

> Here's what I'm trying to do. When I click on a tr i'd like it to hide
> then re-style the table to alternate gray rows.
>
> So on click I hide the tr then run this at the end of the animation/
> hide
>
> $('tr .myToggle').removeClass('gray');
> $('tr .myToggle').not(':hidden').not(':even').addClass('gray');
>
> I want to know if there is a better way of writing the second line:
> $('tr .myToggle').not(':hidden').not(':even').addClass('gray');
>
> I've tried:
> $('tr .myToggle:not(':hidden'):odd').addClass('gray');//does not work
>
> And some other variations on that. If i leave off the :not(':hidden')
> i'll get all rows whether hidden or not, which means coloring odd or
> even rows will not work, it won't look stripped.
>
> Anyway does anyone know how to do this in the selector? Or could you
> point me to some documentation on how to write selectors?
>
> Thanks!

Re: Selectors

by Karl Swedberg-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

this should do it:

$('tr .myToggle:visible:odd').addClass('gray');

--Karl

____________
Karl Swedberg




On Nov 2, 2009, at 4:31 PM, Manimal wrote:

Here's what I'm trying to do. When I click on a tr i'd like it to hide
then re-style the table to alternate gray rows.

So on click I hide the tr then run this at the end of the animation/
hide

$('tr .myToggle').removeClass('gray');
$('tr .myToggle').not(':hidden').not(':even').addClass('gray');

I want to know if there is a better way of writing the second line:
$('tr .myToggle').not(':hidden').not(':even').addClass('gray');

I've tried:
$('tr .myToggle:not(':hidden'):odd').addClass('gray');//does not work

And some other variations on that. If i leave off the :not(':hidden')
i'll get all rows whether hidden or not, which means coloring odd or
even rows will not work, it won't look stripped.

Anyway does anyone know how to do this in the selector? Or could you
point me to some documentation on how to write selectors?

Thanks!