SHOW:
|
|
- or go back to the newest paste.
1 | function nextInDOM(_selector, _subject) { | |
2 | var next = getNext(_subject); | |
3 | while(next.length != 0) { | |
4 | var found = searchFor(_selector, next); | |
5 | if(found != null) return found; | |
6 | next = getNext(next); | |
7 | } | |
8 | return null; | |
9 | } | |
10 | function getNext(_subject) { | |
11 | if(_subject.next().length > 0) return _subject.next(); | |
12 | return getNext(_subject.parent()); | |
13 | } | |
14 | function searchFor(_selector, _subject) { | |
15 | if(_subject.is(_selector)) return _subject; | |
16 | else { | |
17 | var found = null; | |
18 | _subject.children().each(function() { | |
19 | found = searchFor(_selector, jQuery(this)); | |
20 | if(found != null) return false; | |
21 | }); | |
22 | return found; | |
23 | } | |
24 | return null; // will/should never get here | |
25 | } | |
26 | ||
27 | jQuery('.toggle-trigger').on('click', function(e) { | |
28 | e.preventDefault(); | |
29 | - | var target = jQuery(this); |
29 | + | var target = jQuery('.toggle-text'); |
30 | console.log(nextInDOM(target, jQuery('.toggle-trigger'))); | |
31 | }); |