pradeep
pradeep

Reputation: 1

How to auto click button in knockout js

I have the below button on my page. I want below button to be auto clicked when this page gets loaded. I've tried following various suggestions on the net but I'm unable to find a solution. Any help is appreciated.

 <a data-bind="click: $root.addtocart" class="w-button btn-large" 
    style="text-decoration: none!important;" id="redeemButton">
                        Redeem Now                                                                               
 </a>

Upvotes: 0

Views: 649

Answers (2)

G&#244;T&#244;
G&#244;T&#244;

Reputation: 8053

Do it directly in the creation of your viewmodel:

function MyViewModel(){
    this.addtocart = function(){
      //Some code
    }
    this.addtocart(); // <-- here
}

Upvotes: 3

Isha Goyal
Isha Goyal

Reputation: 105

you can add a ready function in your javascript like this..

<script>
    $("document").ready(function () {
        window.getElementById("redeemButton").click();
    });
</script>

Upvotes: 0

Related Questions