I’m trying to do a touchBased HTML application, and was testing it on iPad 2. However, there seems to be some issue with the custom attributes in HTML.
here is my code
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
document.addEventListener('mouseup',onTouchReleased, true);
document.addEventListener('touchend',onTouchReleased, true);
function onTouchReleased(e) {
// Capture the event
if(e.preventDefault)
e.preventDefault();
if(e.stopPropagation)
e.stopPropagation();
console.log(e.target);
console.log(e.target.getAttribute("itemindex"));
}
</script>
</head>
<body>
<img itemindex="0" src="video.jpg"/>
<div itemindex="1">HELLO1</div>
<p itemindex="2">HELLO2</p>
</body>
</html>
when i run it on Chrome/Safari on my PC, i’m able to see the correct itemindex in the console when i click on the item.
However, on iPad2, i get the itemindex of <img> as 0, which is correct, but in case div or p the itemIndex is returned as an Error.
TypeError: Result of expression ‘e.target.getAttribute'[undefined] is not a function
Can someone explain this please, and also enlighten me on any workaround available.
You need to use
touchendinstead ofmouseupevent for touch devices.Touch based devices didn’t support many mouse events such as
mouseup,mousedown,mousemove,mouseover,mouseoutbut supportsclickevent. You can try your code withclickevent too.Update
If you need to attach event to the
documentyou can use following snippet using elementFromPoint functionFor example: