Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple word counter #507

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions Simple-Word-Counter.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container{
width: 100%;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-right: auto;
margin-left: auto;
}
.content{
background-color: red;
padding: 30px 22px;
border-radius: 7px;
color: #fff;
}
.content h1{
padding-bottom: 20px;
}
.inp{
width: 550px;
height: 200px;
resize: none;
font-size: 19px;
padding: 10px;
border: none;
border-radius: 6px;
border: none;
outline: none;
}
.count{
display: flex;
align-items: center;
justify-content: space-between;
padding: 7px;
font-size: 19px;
}
#totalchar{
color: slateblue;
}
#remainchar{
color:blue;
}
</style>
</head>
<body>
<div class="container">
<div class="content">
<h1>Real-time Character Counter</h1>
<textarea id="inp" class="inp" placeholder="please write your text here" maxlength="100"></textarea>
<div class="count">
<h4>Total Characters: <span id="totalchar"></span></h4>
<h4>Remaining: <span id="remainchar"></span></h4>
</div>
</div>
</div>
<script>

const text = document.getElementById("inp");
const totalchar = document.getElementById("totalchar");
const remainchar = document.getElementById("remainchar");


text.addEventListener("keyup", ()=>{
totalchar.innerText = text.value.length;
remainchar.innerHTML = text.getAttribute("maxLength")- text.value.length;
});

</script>
</body>
</html>