HREF pointing to a button

Asked

Viewed 896 times

3

How to point a HREF to a button of the type submit hidden? Hidden/invisible is because the button will be using the attribute hidden.

  • 1

    You’ve had some answers, maybe right and maybe wrong but it’s your fault. What exactly do you mean by "hidden button"? If, by chance, it is the fact that the button is visible on the page, but only outside the user’s view because the form and long and the page needs to be scrolled (scroll), what you actually want is a anchovy (or Bookmark): http://www.hypergurl.com/anchors.html

3 answers

3

A href pure does not do what you want, but a label with for can help you. Remembering that you can leave the stylized label as you think best.

See a demonstration:

<label id="remoto" for="escondido">Clique --> [aqui no texto] <-- em vez de clicar no botão ao lado. </label>

<button id="escondido" onclick="alert('fui clicado!')">Eu vou estar escondido</button>

But if you "really need" to be a a, the other answers can get around the problem of a javascript.

3

Maybe that’s what you’re looking for:

<a href="javascript:$('#botao').click()">Link maneiro</a>

3


Bacco’s answer must be the solution to the problem, but it is not a HREF.

If you really want to go to HREF you can use:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<a href="javascript: $('button').click()">Clique aqui para ganhar um alerta</a>


<button style="display:none;" onClick="alert('meu alerta')"></button>

Explanations:

The button has a parameter onClick which then, when clicked, displays the alert, this "function" may not exist, especially if using the type as submit, in a form, for example. The button also has a style with the display as none, to hide your display.

The link (a href) has a JQuery with the function .click(). This function performs a click on the button chosen. If you have problems or doubts to select ("set") the button read the Jquery documentation in https://api.jquery.com/category/selectors/.

In general and more common for ITS USE should be:

  • .classe (ex: $('.botao') if there is any class='botao').
  • #id (ex: $('#botao') if there is any id='botao').
  • tag (ex: $('button') if there is any <button>).
  • tag[atributo=valor] or tag[atributo] (ex. $('button[type=submit]') if there is any <button type='submit'>).

The higher the level of 'hierarchy' the lower the chance of conflicts (example there are two buttons and a wrong one is triggered).

Browser other questions tagged

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