-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextarea_2.html
76 lines (72 loc) · 1.59 KB
/
textarea_2.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
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>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0px;
padding: 0px;
box-sizing: border-box;
font-family: serif;
}
body{
display: flex;
justify-content: center;
align-items: center;
background: #777;
}
body,
html{
height: 100%;
}
div{
width: 320px;
height: 200px;
/* background-color: red; */
display: flex;
align-items: center;
justify-content: center;
position: absolute;
}
textarea{
width: 300px;
height: 150px;
/* background-color: red; */
padding: 8px;
color: #fff;
border: 5px solid green;
border-radius: 5px;
background-color: #111;
caret-color: rgb(0, 255, 157);
resize: none;
outline: none;
font-weight: bold;
text-decoration: none;
}
p{
position: absolute;
bottom:0px;
right: 20px;
display: none;
}
</style>
</head>
<body>
<div class="con">
<textarea placeholder="Write Something..." id="text-area" onkeyup="count();"></textarea>
<p id="p"><span id="count">0</span>/200</p>
</div>
<script>
function count(){
let txt = document.getElementById('text-area').value.length;
document.getElementById('count').innerHTML=txt;
if(txt>=200) document.getElementById('text-area').style.borderColor='red';
if(txt<200) document.getElementById('text-area').style.borderColor='green';
if(txt>=200) document.getElementById('p').style.color='red';
if(txt<200) document.getElementById('p').style='green';
if(txt >=1 ) document.getElementById('p').style.display = 'block';
}
</script>
</body>
</html>