W3C validation error with data-href

后端 未结 4 1032
时光说笑
时光说笑 2021-01-17 00:46

I am getting one validation error due to my use of data-href=\"\" in the context of making a whole DIV clickable. The JS and HTML is below. What could I do to make this W3C

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-17 01:24

    You cool with adding the attribute through jQuery? Or do we need a more dynamic solution?

    $(".linked").attr('data-href', 'link.html').click(function(){
      window.location = $(this).attr("data-href");
      return false;
    });
    

    also:

    Considering that this isn't a WC3 compliant method have you thought about moving this into the Title attribute? Remove the '.html'line, and in your click function:

    HTML:

    jQuery

    $(".linked").click(function(){
      var dataHref = $(this).attr('title');
      window.location = dataHref.html;
      return false;
    });
    

    Then again, we run into issues with propagation. I don't know how your links are being propagated, whether you hard-code them or you dynamically create them with server side script, so the latter and previous solutions still not might be good enough for you.

    I was downvoted, as the OP said that the solution provided did not work -- The solution provided works completely fine. Please see the fiddle below, and make sure you don't have errors in your javascript before you downvote someone.

    http://jsfiddle.net/n68A8/

提交回复
热议问题