Attribute href exclusively for goal <a></a>?

Asked

Viewed 106 times

3

It is correct to put the attribute href in a mark other than a.

Example:

<ul>
  <li href="#page1">Page1</li>
  <li href="#page2">Page2</li>
  <li href="#page3">Page3</li>
  <li href="http://www.google.fr">Page3</li>
</ul>

Apparently it worked in my case, but that’s correct?

  • 1

    What do you call "worked"? Here it is simply ignored. It may be that your browser does something out of the standard and uses href for something, but it is "invention" of the manufacturer. .

  • In the example of my post clearly does not work, but integrating in my app is working put. What problems can I find in the future ?

  • 2

    The problem you already found, which is "work". It’s not supposed to work, if "works" there is something wrong with the APP right now, and not in the future. When something works when it shouldn’t, it’s a sign of something wrong too.

  • kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk !!!

  • 1

    Seriously, I’m not "joking," no, it would be absurd to expect something that shouldn’t be like this, because the result is unpredictable. It can be a coincidence and only work in rare cases. It can be a JS that is using the links, and not the webview or browser. You can’t trust this at all.

  • 2

    The exception to this would be you find in the official documentation of the platform something like this: "Support for href has been extended in all elements ..." etc, so it would be official. Otherwise, it is better not to risk.

  • 1

    I fully understand your cautionary tendencies, and thanks !

Show 2 more comments

2 answers

6


Is incorrect in li. You can already see that it does not work in the question example. This attribute is specified as belonging to some tags, as <a>, <area>, <base> and <link>. So when used elsewhere it is considered a custom attribute and will probably be disregarded.

MDN documentation on attributes.

Documentation in the W3C.

  • In the example of my post clearly does not work, but integrating in my app is working put. What problems can I find in the future ?

  • It is possible that the renderer you are using will accept this, but it is not official and should not be used. The question has no details about this renderer. If you have something that officially says you can use it, then you can if you want it to only work on it. Working is different from being right. Things work by coincidence, and this is not enough if you want to do the right thing.

1

I believe it is incorrect:

According to W3C :

4.4.7 The li element Content The following: Global Attributes

Content attributes:Global attributes and href, is not a global attribute.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.