Hello. I’m doing the project in clean Javascript. But I can’t find how to add autocomplete to it. I googled but it seems everybody does the project in jQuery, so I can’t find the right code for me. Can anybody help me?
const getRandomLinks = () => {
const value = input.value;
fetch('https://en.wikipedia.org/w/api.php?format=json&action=opensearch&namespace=0&limit=10&prop=extracts&exintro&explaintext&exsentences=1&exlimit=10&search=' + value + '&origin=*', {method: 'GET'}).then(response => response.json()).then(data => {
result.innerHTML = '';
console.log(data);
const title = data[1];
const content = data[2];
const link = data[3];
for(let i = 0; i < data[3].length; i++) {
const li = document.createElement('li');
const text = li.textContent;
const a = document.createElement('a');
a.href = `https://en.wikipedia.org/wiki/${title[i]}`;
a.setAttribute('target', '_blank');
a.textContent = text;
a.innerHTML = `<strong>${title[i]}</strong><br><br>${content[i]}`;
li.appendChild(a);
result.appendChild(li);
}
}).catch(error => {
if(errorMsg.style.display === 'none') {
errorMsg.style.display === 'block';
} else {
errorMsg.style.display === 'none';
}
});
}