-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs.html
45 lines (38 loc) · 1.16 KB
/
js.html
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
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<input type="input" name="search">
<button name="search">Pretrazi</button>
<ul class="prvaul"></ul>
<ul class="drugaul"></ul>
<script type="text/javascript">
let brojevi = [1, 11, 34, 14, 15, 99];
let input = document.querySelector('input');
let btn = document.querySelector('button');
let body = document.querySelector('body');
const liste = document.querySelectorAll('ul');
btn.addEventListener('click', pretrazi);
function pretrazi(){
const broj = input.value;
for (let i = 0; i < brojevi.length; i++) {
if(broj == brojevi[i]){
const listItem = document.createElement('li');
listItem.textContent=broj;
liste[0].appendChild(listItem);
liste[0].style.backgroundColor = 'green';
break;
}else{
const listItem = document.createElement('li');
listItem.textContent=broj;
liste[1].appendChild(listItem);
liste[1].style.backgroundColor = 'red';
break;
}
}
}
</script>
</body>
</html>