HREF pointing to a button

3

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

    
asked by anonymous 30.03.2016 / 07:31

3 answers

3

Bacco's answer should be the solution to the problem, but it is not an 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><ahref="javascript: $('button').click()">Clique aqui para ganhar um alerta</a>


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

Explanations:

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

The link (the href) has a JQuery with the function .click() . This function effects a click on the chosen button. If you have problems or questions to select ("set") the button read the JQuery documentation at link .

In general and most common for YOUR USE it should be:

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

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

    
30.03.2016 / 09:09
3

Maybe this is what you are looking for:

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

A% pure% does not do what you want, but href with label can help you. Remember that you can leave the label stylized as you see fit.

See a demo:

<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 for , the other answers can work around the a problem with JavaScript.

    
30.03.2016 / 08:49