A tag! it doesn’t need href attribute!

blossom0417
1 min readSep 25, 2019

--

<a href="javascript:;" onclick="' + names[index][0] + '">

I’ve found this code really (many times) since i started working.

I thought the a tag must have a href attribute.

It turned out it’s not.

check this below.

The href attribute on a and area elements is not required; when those elements do not have href attributes they do not create hyperlinks.

So. now

you don’t need to do this <href=”JavaScript;;”> thing.

we just use this and this is definitely valid!

<nav>
<ul>
<li> <a href="/">Home</a> </li>
<li> <a href="/news">News</a> </li>
<li> <a>Examples</a> </li>
<li> <a href="/legal">Legal</a> </li>
</ul>
</nav>

--

--

No responses yet