Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
import { towns } from "./towns.js"; import { html, render } from 'https://unpkg.com/lit-html?module'; function search() { let button = document.querySelector("button") let input = document.getElementById("searchText"); let townsDiv = document.getElementById("towns"); function createTownTemplate(town) { return html`
${town}
` } let townsLis = towns.map(t => createTownTemplate(t)); let ul = document.createElement("ul"); render(townsLis, ul); render(ul, townsDiv) button.addEventListener("click", function (e) { let matches = 0; let searchQuery = input.value; function createActiveLi(town) { return html`
${town}
` } let differentLis = []; towns.forEach(t => { if (t.toLowerCase().includes(searchQuery.toLowerCase())) { matches++; differentLis.push(createActiveLi(t)) } else { differentLis.push(createTownTemplate(t)) } }) render(differentLis, ul); render(ul, townsDiv); let resultDiv = document.getElementById("result"); resultDiv.textContent = `${matches} matches found`; }) } search()
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)