1

I want to use this part of code on my html page, it works fine, but I don't understand how to correct my error on the validator. I put the function in a div but in a we have the same error. Here is the link of the stackoverflow question.

This is the validator error:

Error: Attribute ontouchend not allowed on element div at this point.

Here is the css code:

:hover {
  background: red;
}

In the JS I have:

function fix() {
    var el = this;
    var par = el.parentNode;
    var next = el.nextSibling;
    par.removeChild(el);
    setTimeout(function() {
        par.insertBefore(el, next);
    }, 0);
}

And then in my HTML I have:

<a href="#" ontouchend="this.onclick=fix">test</a>
Community
  • 1
  • 1
coolio83000
  • 119
  • 2
  • 14
  • This part seems fishy to me: `this.onclick=fix` What are you trying to achieve here? – jmargolisvt Sep 26 '16 at 13:01
  • I've a problem with hover on iPhone, iPad, ... when i click on a link, the css hover stay active, with this function, I can remove the css when i touch the screen – coolio83000 Sep 26 '16 at 13:02

1 Answers1

1

The ontouchend attribute is not standardized. It is even not widely supported. This means you can use it in some browsers, but validators will throw warnings.

You can simply ignore it, when it works for you. But this don't mean that this attribute behavior meight not change in the future.

Quotes:

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for the proper prefixes to use in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the spec changes.


Note: This attribute has not been formally standardized. It is specified in the Touch Events – Level 2 Editor's Draft specification and not in Touch Events Recommendation. This attribute is not widely implemented.

Read more about the attribute in the MDN docs here and here.

eisbehr
  • 12,243
  • 7
  • 38
  • 63
  • ahh ok i understand now, there is a safe way to have the same result ? – coolio83000 Sep 26 '16 at 13:09
  • Hmm, I actually don't know one. Maybe a JS library or something. But actually touch events are not standardized, which means, there is no *default way*. I'm sorry. @coolio83000 – eisbehr Sep 26 '16 at 13:12
  • 1
    Yes i thought it was a simple question but i think that i use 2 hours to find a way, so i have to let the css active on touchscreen !! no way to fix it now !! thanks for your help @eisbehr – coolio83000 Sep 26 '16 at 13:14