Static vs. Live NodeList
How do I make an static vs. live nodelist?
What is a static vs. live nodelist? How do you make a static vs. live nodelist? This script and codes were developed by Karl Saunders on 20 November 2022, Sunday.
Static vs. Live NodeList - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Static vs. Live NodeList</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <link rel='stylesheet prefetch' href='https://fonts.googleapis.com/css?family=Roboto:400,500'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="container"> <div class="panel"> <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> <li>Item 4</li> </ul> <button class="btn btn-primary" id="add">Add Item</button> <button class="btn btn-primary" id="count-a">Get Count (getElementsByTagName)</button> <button class="btn btn-primary" id="count-b">Get Count (querySelectorAll)</button> </div>
</div> <script src="js/index.js"></script>
</body>
</html>
Static vs. Live NodeList - Script Codes CSS Codes
body { font-family: 'Roboto'; font-weight: 500;
}
.container { width: 40%; height: 40%; position: absolute; left: 50%; top: 50%; -webkit-transform: translate3d(-50%, -50%, 0); transform: translate3d(-50%, -50%, 0);
}
h4 { margin-bottom: 20px;
}
li { width: 100%; padding: 8px 10px; border: 1px solid #aaa; border-radius: 3px; margin: 0 5px 5px 0;
}
button { background-color: #999; border: 1px solid #999; border-radius: 3px; color: #fff; font-family: "Roboto"; font-weight: 500; padding: 5px 10px; cursor: pointer;
}
button.btn-primary { background-color: #0077db; border-color: #0077db;
}
button.btn-primary:hover { background-color: #007fea; border-color: #007fea;
}
Static vs. Live NodeList - Script Codes JS Codes
var countA = document.getElementById('count-a');
var countB = document.getElementById('count-b');
// Live
var live = document.getElementsByTagName('li');
// Static
var static = document.querySelectorAll('li');
// Get the count returned from getElementsByTagName
countA.addEventListener('click', function(e) { alert(live.length);
}, false);
// Get the count returned from querySelectorAll
countB.addEventListener('click', function(e) { alert(static.length);
}, false);
// Add item
document.getElementById('add').addEventListener('click', function(e) { var list = e.target.parentNode.firstElementChild, item = list.lastElementChild.cloneNode(true); item.textContent = 'Item ' + (list.children.length + 1); list.appendChild(item);
}, false);
Developer | Karl Saunders |
Username | Mobius1 |
Uploaded | November 20, 2022 |
Rating | 3 |
Size | 2,748 Kb |
Views | 12,144 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Pure CSS Animated Folder Icon | 3,019 Kb |
CRT TV Effect | 6,390 Kb |
A Pen by Karl Saunders | 11,295 Kb |
Solitaire Win Animation | 2,615 Kb |
One-Time Events | 1,468 Kb |
DVD Screensaver | 3,188 Kb |
Pure CSS Windows Loader | 2,724 Kb |
Vanilla DataTables - AJAX | 0 Kb |
Classic Snake in Vanilla Javascript | 5,117 Kb |
Gumball Watterson - Pure CSS | 0 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Vertically rotating text with CSS | Nopr | 2,141 Kb |
Twitch JSON API | Jvhti | 2,808 Kb |
Page Transitions in Backbone | Mikefowler | 3,691 Kb |
Fixed with using Calc | Tomleo | 2,542 Kb |
Content Changer | Cliffpyles | 4,538 Kb |
A Pen by Final Boss tommyb9 | FBtommyb9 | 55,354 Kb |
AngularJS Skills | Supro | 3,312 Kb |
Electric worm | Jeffibacache | 2,377 Kb |
Navcube | Wbarlow | 4,775 Kb |
3D-box | Parthviroja | 2,346 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!