I have the following HTML Code. Clicking on the Buy now for 200 will show the below pop up with Buy now, ok and close
<button class="btn-standard buyButton currency-coins">Buy Now for 200</button>
<div class="dialog-body">
<button class>
span class="btn-text">Ok</span>
<span class="btn-subtext"></span>
</button>
<button class>
<span class="btn-text">Ok</span>
<span class="btn-subtext"></span>
</button>
</div>
I want to automatize the process, and I did something like this in javascript but it didn't work for the last step, click on OK .
So below is my code.
$("button:contains('Buy Now')").on('click', function(){
$("span:contains('Ok')").click();}); //alert("hello") is working, but click on OK button didn't
----------------------------
$("button:contains('Buy Now')").click(); // is doing nothing for Ok button click.
You want to trigger the click event of the span on the click of the 'Buy Now' button, if I understood correctly.
The code you have should work. All you need to do is create a function to do something about the click event of the span.
$("button:contains('Buy Now')").on('click', function() { $("span:contains('Ok')").trigger('click'); return false; }); $("span:contains('Ok')").on('click', function() { //do something here alert("This works"); });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <button class> Buy Now </button> <div class="dialog-body"> <button class> <span class="btn-text">Ok</span> <span class="btn-subtext"></span> </button> <button class> <span class="btn-text">Cancel</span> <span class="btn-subtext"></span> </button> </div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.