File tree 2 files changed +60
-11
lines changed 2 files changed +60
-11
lines changed Original file line number Diff line number Diff line change 9
9
</ head >
10
10
< body >
11
11
12
+
12
13
< ul class ="level-1 ">
13
14
< li class ="item-i "> I</ li >
14
15
< li class ="item-ii "> II
27
28
< li class ="item-iii "> III</ li >
28
29
</ ul >
29
30
31
+ < script type ="text/javascript ">
30
32
31
- < ul >
32
- < li class ="first "> list item 1</ li >
33
- < li > list item 2</ li >
34
- < li class ="third-item "> list item 3</ li >
35
- < li > list item 4</ li >
36
- < li class ="end "> list item 5</ li > q
37
- </ ul >
33
+ var li = $ ( '.item-ii' ) ;
34
+
35
+ console . log ( li . find ( 'li' ) )
38
36
39
37
40
- < script type ="text/javascript ">
41
38
42
- console . log ( document )
39
+ function sibling ( n , elem ) {
40
+ var matched = [ ] ;
41
+ for ( ; n ; n = n . nextSibling ) { //如果存在下一个兄弟节点
42
+ if ( n . nodeType === 1 && n !== elem ) { //是元素节点,且不是当前选择器元素
43
+ matched . push ( n ) ;
44
+ }
45
+ }
46
+ return matched ;
47
+ }
43
48
44
- console . log ( document . querySelectorAll ( '.first ' ) [ 0 ] )
49
+ var ul = document . querySelectorAll ( '.level-2 ' ) [ 0 ] ;
45
50
46
51
47
- console . log ( document . body . appendChild ( document . querySelectorAll ( '.first' ) [ 0 ] ) )
48
52
49
53
</ script >
50
54
Original file line number Diff line number Diff line change
1
+ <!doctype html>
2
+ < html >
3
+ < head >
4
+ < meta http-equiv ="Content-type " content ="text/html; charset=utf-8 "/>
5
+ < title > 参考对照学习</ title >
6
+ < script src ="core.js "> </ script >
7
+ < script src ="sizzle.js "> </ script >
8
+ < script src ="other.js "> </ script >
9
+ </ head >
10
+ < body >
11
+
12
+
13
+ < ul >
14
+ < li > list item 1</ li >
15
+ < li > list item 2</ li >
16
+ < li class ="third-item "> list item 3</ li >
17
+ < li > list item 4</ li >
18
+ < li > list item 5</ li >
19
+ </ ul >
20
+
21
+ < script type ="text/javascript ">
22
+
23
+
24
+ function sibling ( n , elem ) {
25
+ var matched = [ ] ;
26
+ for ( ; n ; n = n . nextSibling ) {
27
+ if ( n . nodeType === 1 && n !== elem ) {
28
+ matched . push ( n ) ;
29
+ }
30
+ }
31
+ return matched ;
32
+ }
33
+
34
+ var thirdItem = document . querySelectorAll ( 'third-item' ) [ 0 ]
35
+
36
+ var results = sibling ( thirdItem . parentNode . firstChild , thirdItem )
37
+
38
+ console .
39
+
40
+ // console.log( document.body.appendChild( document.querySelectorAll('.first')[0]) )
41
+
42
+ </ script >
43
+
44
+ </ body >
45
+ </ html >
You can’t perform that action at this time.
0 commit comments