I need to make an auto click on a class button (HELP)

Asked

Viewed 609 times

0

I need to perform an auto click on this button:

<button tabindex="-1" class="btn btn-inverse btn-large"> Botao1 </button>

However there are several similar classes, I have tried using the [Number]. click to set the specific click, only the number sometimes changes, then click on a different button.. I need help to click exclusively on the button above.

  • Hello, welcome to Sopt, it will be good for your question if you add the code you have tried so far, so click on [Edit]

1 answer

0

You can place a new element called id in the <button>, would look like this:

<button tabindex="-1" class="btn btn-inverse btn-large" id="myButton"> Botao1 </button>

By doing this you can catch the event click of that element by jQuery:

$("#myButton").click(function() {
  console.log("Button click!")
})

Or, if you’re using pure javascript, you can do the following:

document.getElementById("myButton").onclick = function() {
    console.log("Button click!")
}
  • But I will have to keep adding the ID all the time, because I need to update the page all the time , and update the id some ..

  • @lololololo you will write the ID in your HTML and do not add the ID via javascript. Putting in HTML you will even have to refresh the page

  • @lololololo the Salatiel is right. Maybe we don’t understand what you’re trying to do, if you can, post more parts of the code to understand better

Browser other questions tagged

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