I want the index of the search results when they are being clicked and I have used the following code:-
$('#results').append('<div class="res"><p class="clickable"><a id="select">'+dis[searchResult[i]]+'</a></p></div>');
var g = document.getElementById("select");
for (var j = 0; j<g.dis.length; j++)
{
g.addEventListener('click',function(index){
console.log(index);
});
}
But that gives the following error:-
search83.js:27 Uncaught TypeError: Cannot read property 'length' of undefined
at HTMLInputElement.<anonymous> (search83.js:27)
at HTMLInputElement.dispatch (jquery.min.js:2)
at HTMLInputElement.v.handle (jquery.min.js:2)