Static vs. Live NodeList

Developer
Size
2,748 Kb
Views
12,144

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 Previews

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);
Static vs. Live NodeList - Script Codes
Static vs. Live NodeList - Script Codes
Home Page Home
Developer Karl Saunders
Username Mobius1
Uploaded November 20, 2022
Rating 3
Size 2,748 Kb
Views 12,144
Do you need developer help for Static vs. Live NodeList?

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!

Karl Saunders (Mobius1) Script Codes
Create amazing blog posts with AI!

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!