> http://www.intrepidengineer.com/toggle-behavior-2.html
>
> I've posted another example that demonstrates this issue again, using
> toggle() here, which seems like the simplest approach, doesn't work
> right, because the buttons get out of sync. If I wrote this myself
> just using style.display, it wouldn't get out of sync. Perhaps this
> is a better demonstration of what I would expect to work versus the
> last example.
This does show some behavior that might seem odd. To make it clear,
the basic page has a collection of five books, along with their
authors. Two of the books are identified as favorites. The author
elements are inside the book element, looking something like:
B1(A1), B2(A2), FB3(A3), B4(A4), FB5(A5)
where B is a book, FB is a favored book, and A is an author. There
are also two buttons, Toggle Authors (TA) and Toggle Favorites (TF).
After TA, you get, as expected:
TA: B1, B2, FB3, B4, FB5
and after TF, you get
TF: FB3(A3), FB5(A5)
Both restore the original after two calls:
TA-TA: B1(A1), B2(A2), FB3(A3), B4(A4), FB5(A5)
TF-TF: B1(A1), B2(A2), FB3(A3), B4(A4), FB5(A5)
But things get somewhat strange after you start combining them:
TF-TA-TF: B1(A1), B2(A2), FB3, B4(A4), FB5
and
TF-TA-TF-TA: B1, B2, FB3(A3), B4, FB5(A5)
A reasonable guess would have had:
TF-TA-TF: B1, B2, FB3, B4, FB5
and
TF-TA-TF-TA: B1(A1), B2(A2), FB3(A3), B4(A4), FB5(A5)
This expected behavior is easy to accomplish using, say a class with
"display: none".
The difference between these two:
http://jsbin.com/ajuya (code http://jsbin.com/ajuya/edit)
http://jsbin.com/alapo (code http://jsbin.com/alapo/edit)
is that the first uses toggle and the second uses toggleClass.
I haven't looked at the implementation of toggle, but it seems as if
it was taking a shortcut that may not be warranted. Are there cases
where the current behavior is really preferred to the more obvious one
in which "display: none" (or whatever) is added to or removed from all
matching elements?
-- Scott
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---