Question

I have the following code:

$( "#check-button" ).on( "click", function() {
    $("#button_cart").click();
    $('.checkout-button').click();
});

I have this jQuery click event. What I want to do is, on clicking the check-button, the first line inside the function is updating the cart (which reloads the page) and then the second line inside the function is the checkout button, which takes me to the next (checkout) page.

But here only the first event is firing. Is this because the page is reloaded on "button-cart" clicking? How do I solve it?

Était-ce utile?

La solution 2

Here is how i did it: Using localstorage.

Just saved the value of someVariable on check-button click ( along with button-cart click) and on page reload i checked if the value is set. If it is set, i unset it and clicked the next button. Here is the link

This was really great help from SO. Thank u SO

Autres conseils

That's correct. The second click actually could be working but in some kind of limbo between the click and the load and you wont see it.

The solution is to "handle" the reload event, I put it between "" because this event can't be handled ( as far as I know) but you can make some hacks.

First, why is reloading the page? Are you adding new content?

In this case just call the click in the content added with a load handler like $(document).ready();

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top