<div><style> #searchalphabet{ width: 90%; padding: 10px; border-radius: 5px; } </style> <input type="text" id="searchalphabet" placeholder="Search..." onkeyup="filterTerms()"> <div id="Label1"></div> <script> var terms = []; // Array to store the original list of terms function cat(json) { var label = json.feed.category; var lst = []; var titleText = document.getElementById('titlehref').textContent; var lastChar = titleText.charAt(titleText.length - 1); console.log(lastChar); for (var i = 0; i < label.length; i++) { var term = label[i].term; if (term.charAt(0).toLowerCase() === lastChar.toLowerCase()) { lst.push(term); } } // Sort the list in ascending order lst.sort(); // Store the sorted terms for later use terms = lst; // Display the initial list displayTerms(terms); } function displayTerms(terms) { var lst = terms.map(function(term) { return '<li><a dir="ltr" href="https://www.malaykord.com/search/label/' + encodeURIComponent(term) + '">' + term + ''; }); var result = '<div class="widget-content list-label-widget-content">'; result += '<ul>'; result += lst.join(''); result += ''; result += '</script></div>