Skip to content

Commit 13e47b0

Browse files
sample programs
1 parent fd01248 commit 13e47b0

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

checkboxes/checkboxes.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
## SELECT / UNSELECT ALL CHECKBOXES
2+
3+
```html
4+
<table>
5+
<thead>
6+
<tr>
7+
<th>
8+
<button id="selectAll" type="button">Select All</button>
9+
</th>
10+
<th>Name</th>
11+
<th>Company</th>
12+
<th>Location</th>
13+
</tr>
14+
</thead>
15+
<tbody>
16+
<tr>
17+
<td>
18+
<input type="checkbox" name="checkbox" />
19+
</td>
20+
<td>Hari</td>
21+
<td>Mutual of Omaha</td>
22+
<td>Omaha</td>
23+
</tr>
24+
<tr>
25+
<td>
26+
<input type="checkbox" name="checkbox" />
27+
</td>
28+
<td>Sundaragopalan</td>
29+
<td>CUB</td>
30+
<td>Hyderabad</td>
31+
</tr>
32+
</tbody>
33+
</table>
34+
```
35+
36+
```js
37+
const selectAllButton = document.getElementById("selectAll");
38+
39+
selectAllButton.addEventListener("click", function() {
40+
const checkboxes = document.querySelectorAll("input[type=checkbox]");
41+
// check if button has allChecked class
42+
if (selectAllButton.classList.contains("allChecked")) {
43+
checkboxes.forEach(checkbox => checkbox.checked = false);
44+
} else {
45+
checkboxes.forEach(checkbox => checkbox.checked = true);
46+
}
47+
48+
selectAllButton.classList.toggle("allChecked");
49+
})
50+
```

progressBar/progressBar.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## Progress Bar with Vanilla JS
2+
3+
### HTML
4+
5+
```html
6+
<div class="progressBarContainer">
7+
<div class="progressBar" />
8+
</div>
9+
10+
<button onclick="updateProgress(2)">Start</button>
11+
```
12+
13+
### CSS
14+
15+
```css
16+
.progressBarContainer {
17+
width: 400px;
18+
height: 30px;
19+
margin: 40px;
20+
background-color: light-grey;
21+
}
22+
23+
.progressBar {
24+
background-color: green;
25+
height: 100%;
26+
width: 0%;
27+
}
28+
```
29+
30+
### JS
31+
32+
```js
33+
const updateProgress = delayInSeconds => {
34+
let atPercent = 0;
35+
const progressBar = document.querySelector(".progressBar");
36+
37+
const interval = setInterval(() => {
38+
atPercent++;
39+
progressBar.style.width = `${atPercent}%`;
40+
progressBar.style.innerText = `${atPercent}%`;
41+
42+
if (atPercent >= 100) {
43+
clearInterval(interval);
44+
}
45+
}, (delayInSeconds * 1000) / 100);
46+
}
47+
```

0 commit comments

Comments
 (0)