문제

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?

도움이 되었습니까?

해결책 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

다른 팁

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();

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top