문제

I'm working on an web app for iOS Safari. I've got a search input with an autocompletion/suggestions list below it. With javascript I add the suggestions to the list:

document.getElementById('selector_autocomplete').innerHTML
 += '<span ontouchstart="selector_select(' + i + ');">' + name + '</span><br />';

Now the problem is that the ontouchstart doesn't seem to get fired when touching the element.

I've tested it with console.log(); etc. But nothing happens.

How can I get it to work?

도움이 되었습니까?

해결책

The ontouchstart="" attribute does not add a listener to the node when inserted into the DOM. Only at the first load of the page.

Using addEventListener('touchstart', ...); on the items after inserting them is the solution here.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top