Reputation: 1022
I'm trying to implement to validator.js plugin for bootstrap found here : https://1000hz.github.io/bootstrap-validator/
I want to hook into the submit event.
The following is written in the documentation for the plugin : "Be sure your submit handler is bound after the plugin has been initialized on your form"
I have written my submit handler like this and everything seems to work fine.
$( document ).ready(function() {
$('#form').validator().on('submit', function (e) {
if (e.isDefaultPrevented()) {
console.log("invalid form");
} else {
console.log("everything looks good!");
}
})
});
But can I be sure that this will work all the time?
How can I be sure that the plugin has already been initialized?
Upvotes: 2
Views: 179
Reputation: 728
A page can't be manipulated safely until the document is ready, because of:
$(document).ready(function(){...});
If you want load your functions after entire page (images or iframes) not just the DOM is ready use:
$(window).on("load", function(){...})
Upvotes: 2