Simulate Javascript Click [closed]

-1

I found a code that simulates the click of a button, but I need to call a function in javascript and pass a string, how would that look?

document.getElementById("meuElemento").click();
    
asked by anonymous 11.10.2017 / 14:48

2 answers

1

You can call the function directly also:

function evento(string){
  console.log(string);
}
<input type="button" id="meuElemento" onclick="evento('Teste')">
    
11.10.2017 / 14:53
0

put like this:

  <a href="#" id="meuElemento" onclick="funcao('minha string')">clique aqui.</a>

        <script>
            function funcao(string) {
                alert(string)
            }
            document.getElementById("meuElemento").click();
        </script>
    
11.10.2017 / 14:53