Answer the question
In order to leave comments, you need to log in
How to execute a script regardless of page readiness?
I have a form page.
There is a handler on the button.
$('.success-pay').click();
But the script is launched only after the page is completely loaded. How can I make it execute as soon as it goes to the page?
Answer the question
In order to leave comments, you need to log in
But how does JS find these very elements with the success-pay class if the page is not ready yet? At the very least, the HTML DOM should load, and in your case, jquery as well. To find and deal with other causes of delays, see the DevTools Network tab .
And it's $('.success-pay').click();
not a handler, but an event trigger.
If you want maximum speed, you can rewrite it in JavaScript and place the code before the closing body tag:
<script>
var el = document.getElementsByClassName('success-pay');
for (var i = 0; i < el.length; i++) {
el[i].click();
}
</script>
<!-- Дальше уже подключайте jquery и прочее -->
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
</body>
what about the meaning? does it take so long for your page to load?
read about how pages are rendered, are you sure that your handler does not slow down loading or break styles?
and if in fact, your handler is in something like $(function(){}) or $(document).ready, because of which it is loaded after the page is loaded. And yes, it doesn't work without jquery, keep in mind.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question