1

I want my webpage to auto click a button when the page is loaded. This is my button:

<button class="configure-product configure-product-simple elementor-button" type="button" data-price="95" data-product_id="1934">Stel samen!</button>

I think this button calls a JS function of a wordpress plugin, so that you open the product configurator. If i copy this button html on another page tho it wont work. It will only work on the product page.

Im very new to developing, so i could really use some help. Does anyone have any ideas how to implement this?

Tijmen
  • 13
  • 3

3 Answers3

2

window.onload = function() {
  document.getElementById("my-button").click();
}
<button id="my-button" class="configure-product configure-product-simple elementor-button" type="button" data-price="95" data-product_id="1934">Stel samen!</button>
fkrzski
  • 255
  • 2
  • 16
2

this is how to do it in jQuery

$(document).ready(function(){ //on document loads (you could change to window also)
  $('#click').click(); // click
})

$(document).ready(function(){
  $('#click').click();
})




$('#click').click(()=>{
  console.log('thanks!');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="click"> Click Meeh </button>

another shorter way to do it in vanilla js

document.onload = document.querySelector('#click').click();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="click" onclick="console.log('hi')"> Click Meeh </button>

other ways to do it

  1. https://stackoverflow.com/a/38517365/18001301
  2. window.onload vs document.onload
Sarout
  • 821
  • 4
  • 25
2

document.getElementById("input").click();

offset82
  • 19
  • 2