I got this code from codepen: https://codepen.io/jsartisan/pen/wKORYL#=
What happens is I put it all in one page but it won't run. I tried to understand what is wrong with it, but it is just like the example in codepen above.
This happened before in other codepen examples but I couldn't figure out the reason why it won't work.
<html>
<head>
<style>
#filter_users {
width:100%;
padding:10px;
}
#users-list {
margin:0;
padding:0;
}
#users-list li {
list-style:none;
padding:10px;
margin:5px 0;
border: 1px solid #e4e4e4;
}
</style>
<script>
var users = [
'Goku',
'Naruto',
'Ichigo',
'Flash',
'Batman',
'Sherlock Holmes',
'Khaleesi',
'Steve Fox'
];
ul = document.getElementById("users-list");
var render_lists = function(lists) {
var li = "";
for (index in lists) {
li += "<li>" + lists[index] + "</li>";
}
ul.innerHTML = li;
}
render_lists(users);
// lets filters it
input = document.getElementById('filter_users');
var filterUsers = function(event) {
keyword = input.value.toLowerCase();
filtered_users = users.filter(function(user) {
user = user.toLowerCase();
return user.indexOf(keyword) > -1;
});
render_lists(filtered_users);
}
input.addEventListener('keyup', filterUsers);
</script>
</head>
<body>
<input type="text" placeholder="Search Users" id="filter_users"/>
<ul id="users-list">
</ul>
</body>
</html>
I expect it to work as in codepen.
` tag. (If you were using `src` rather than inline script, an alternative would be to add `defer` to the `script` tag. But not with inline script.)
– T.J. Crowder Aug 19 '19 at 13:12