Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <img class="a" />
- <img />
- <img class="a" />
- <img class="a" id="active" />
- <img class="a" />
- <img class="a" />
- <img />
- <img class="a" />
- // here's our active element.
- var $active = $('#active');
- // here is the filter we'll be testing against.
- var filter = "img.a";
- // $all will be the final jQuery object with all the consecutively matched elements.
- // start it out by populating it with the current object.
- var $all = $active;
- for ($curr = $active.prev(filter); $curr.length > 0; $curr = $curr.prev(filter)) {
- $all = $all.add($curr);
- }
- for ($curr = $td.next(filter); $curr.length > 0; $curr = $curr.next(filter)) {
- $all = $all.add($curr);
- }
- $('#active')
- .nextAll()
- .each(hideConsecutive)
- .end()
- .prevAll()
- .each(hideConsecutive)
- ;
- function hideConsecutive(index, element) {
- var $e = $(element);
- if (!$e.is(".a")) {
- return false; // this stops the each function.
- } else {
- $e.hide('slow');
- }
- }
- var $all =
- (name == 'prev')
- ? $(this).prevAll()
- : $(this).nextAll();
- if (!matchExpr)
- return $all;
- var $notMatch = $($all).not(matchExpr).filter(':first');
- if ($all.index($notMatch) != -1)
- return $allConsecutive = $all.slice(0, $all.index($notMatch));
- return $all;
- };
- $('#active ~ img.a').hide();
- $('#active ~ img.a')
- var next = $('#active').next('.a');
- var prev = $('#active').prev('.a');
Add Comment
Please, Sign In to add comment