-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery-traversing.html
More file actions
76 lines (60 loc) · 1.63 KB
/
jquery-traversing.html
File metadata and controls
76 lines (60 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div>Empty</div>
<div class="lists">
<ul id="techs">
<li>Linux</li>
<li>Apache</li>
<li>MySQL</li>
<li>PHP</li>
<li>Javascript</li>
</ul>
<ul id="techs2">
<li>JAVA</li>
<li>GROOVY</li>
</ul>
<ul>
<li>Apple</li>
<li>Banana</li>
<li>Peach</li>
</ul>
</div>
<div class="lists">
<ul id="techs3">
<li>Scala</li>
<li>Kotlin</li>
</ul>
</div>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script>
"use strict";
(function(){
// Get me the div parent from the third list
var secondDiv = $("#techs3").parent();
console.log(secondDiv);
// Get the first div with the class lists
$("div.lists").first();
// Get the children from the second ul in the first div with the class lists
var res = $("div.lists").first().children().first().next();
// var res = $("div.lists").first().children().last().prev();
console.log(res);
// Get the list of fruits without adding an id or class on the html
var fruits = $("div.lists").first().children().last().children();
console.log("Fruits");
console.log(fruits);
// Loops inside the list of fruits [froot loops]
fruits.each(function(index, element){
console.log(index + " " + $(element).text());
});
})();
</script>
</body>
</html>