'How do I automatically click this button?
How I can make a script that automatically clicks this button?
<div data-v-2aabe0a6="" class="box-inner">
<span data-v-2aabe0a6="">JOIN</span>
</div>
Solution 1:[1]
this code, if inserted where necessary, will work
document.querySelector('div[data-v-2aabe0a6=""]').click()
Solution 2:[2]
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="" class="join box-inner">
JOIN
</button>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | DividerBeam |
| Solution 2 | Andy |
