Thing I want to do

Execute the hover effect of the PC with the smartphone until the element is touched ~ other elements are touched

jQuery (function ($) {
document.getElementById ('wrap') [0] .setAttribute ('ontouchstart','');
  var touch ='ontouchstart' in document.documentElement || navigator.maxTouchPoints>0 || navigator.msMaxTouchPoints>0;
  if (touch) {
    try {
      for (var si in document.styleSheets) {
        var styleSheet = document.styleSheets [si];
        if (! styleSheet.rules) continue;
        for (var ri = styleSheet.rules.length --1;ri>= 0;ri--) {
          if (! styleSheet.rules [ri] .selectorText) continue;
          if (styleSheet.rules [ri] .selectorText.match (': hover')) {
            //styleSheet.deleteRule (ri);
            styleSheet.rules [ri] .selectorText = styleSheet.rules [ri] .selectorText.replace (': hover',': active');
    } catch (ex) {}
Details of the error

* uncaught typeerror cannot read property'null' of null *

A red underline is drawn from the closing brace of the wrap.


I'm sorry if the question is a sloppy question.

Since I am a js beginner, I do not understand etiquette well, so I think that I should study from the basics and analyze one by one, but I had to solve it in a hurry, so I will help you here. I decided to have it.

  • Answer # 1

    getElementsByTagName ('body') [0],
    I was editing to getElementsById ('wrap') [0],
    It worked fine when I reverted to the original tag name body.

    * Id ='wrap' exists properly.

    I'm not sure why, but I solved it for the time being ...
    I'm sorry for the unclear questions and solutions that made me feel rough.