-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
35 lines (31 loc) · 1.03 KB
/
script.js
File metadata and controls
35 lines (31 loc) · 1.03 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
function addToCloud(menu) {
let tagCloud = document.getElementById("language-cloud")
let tagCloudChildCount = tagCloud.childNodes.length;
console.log(tagCloudChildCount);
for (let i = 0; i < tagCloudChildCount; i++) {
if (tagCloud.childNodes[i].value == menu.value) {
alert("already exists");
return;
}
}
let newTag = document.createElement("option");
newTag.setAttribute("value", menu.value);
let tagContent = document.createTextNode(menu.options[menu.selectedIndex].text);
newTag.appendChild(tagContent);
tagCloud.appendChild(newTag);
}
var tagCloud = document.getElementById("language-cloud");
tagCloud.addEventListener('click', function(e) {
tagCloud.removeChild(e.target);
})
/*
Test HTML code:
<select id="language-menu" onChange="addToCloud(this)">
<option value="ar">Arabic</option>
<option value="en">English</option>
<option value="fr">French</option>
<option value="de">German</option>
</select>
<div id="language-cloud">
</div>
*/