Link without using href

Asked

Viewed 2,938 times

-2

Is there any way to use links without the tag <a href>. For example <a href="exemplo">exemplo</a> there’s another way to do this?

  • You want this link to be redirected automatically, or the user should click on it?

  • 7

    Why not use the href property of the tag ?

4 answers

10


The only alternative is using Javascript, inline in HTML or with event headphone.

You should keep in mind that in terms of SEO and semantics to tag <a> is the correct one to use. But if you still want to not use an anchor you can use it like this (taking into account the stylization of the mouse pointer, as @Maniero indicated):

event headphone

HTML

<div id="link" data-link="site.com">exemplo</div>

Javascript

document.getElementById('link').addEventListener('click', function () {
  var href = this.dataset.link;
  window.location = href;
});

inline

HTML

<div onclick="location.href = 'site.com'">exemplo</div>
  • Event headphone would be correct Reader ? would not have a more usual word to put or should be this one ?

  • @Gabrielrodrigues in Portugal is usual, and is an acceptable translation for Liener. In Brazil, we use more when we are at the doctor :) http://michaelis.uol.com.br/moderno/portugues/index.php?lingua=portugues-portugues&palavra=auscultar

5

1

You can perform the following:

HTML

<a class="meuClick" style="cursor:pointer;">Aqui</a>

In his javascript:

$("a").on('click', '.meuClick', function()
{
   //faça algo
}

Using this method, it recognizes even if it is a link from GIFT (or dynamic).

0

Not unlike the answers "inline" already presented but using window.open()

<a onclick="window.open('/','_self', 'noopener')" style="cursor:pointer;">SOpt</a>

The difference is by the second argument: _self to the same window or _blank to open in a new tab

Browser other questions tagged

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