Reputation: 11
I have a jsp page with jquery-ui somehow it's taking time to load . I have hide the dom and onload function I am writing the following code
setInterval(function(){
if(typeof jQuery.ui !=undefined )
{
$(document.body).css("visibility", "visible");
}
},5000)
I don't want to run the function once condition get true , how to achieve it
Upvotes: 0
Views: 56
Reputation: 1885
Write your all code inside the:
$( document ).ready(function() {
console.log( "ready!" ); //Here you can put all the code
});
Once you DOM(Document object model) is ready then your js code will run, which is written inside the document ready function.
Upvotes: 4
Reputation: 109
Put your code inside a $( document ).ready()
block. As shown below.
$( document ).ready(function() {
console.log( "ready!" );
});
OR shorthand for $( document ).ready()
$(function() {
console.log( "ready!" );
});
You may refer to this documentation for more information. https://learn.jquery.com/using-jquery-core/document-ready/
Upvotes: 1