Home > Software design >  How do I automatically click this button?
How do I automatically click this button?

Time:05-02

How I can make a script that automatically clicks this button?

<div data-v-2aabe0a6="" >
  <span data-v-2aabe0a6="">JOIN</span>
</div>

CodePudding user response:

this code, if inserted where necessary, will work

document.querySelector('div[data-v-2aabe0a6=""]').click()

CodePudding user response:

Maybe rethink your CSS. Have a new meaningful class name like "join" which describes the button, and use that alongside "box-inner". Then target "join".

(Sidenote: maybe change that markup to something more semantically meaningful too by using <button>.)

const button = document.querySelector('.join');
button.addEventListener('click', handleClick, false);

function handleClick() {
  console.log('Joined!');
}

button.click();
.join { padding: 1em 2em; background-color: lightgreen; }
.join:hover { cursor: pointer; }
.box-inner { box-shadow: 5px 10px 5px pink inset; }
<button data-v-2aabe0a6="" >
  JOIN
</button>

  • Related