Reputation: 5236
I have an HTML document and I want to check is there any visible div element with Jquery after page load.
After document ready function multiple div elements will be generated by some js function and I want to check these div elements generated or not.
I have found below code but it checks with ID but I don't have any ID;
function checkContainer () {
if($('#divID').is(':visible'))){
createGrid();
}else {
setTimeout(checkContainer, 50);
}
}
Upvotes: 2
Views: 244
Reputation: 377
Why don't you try searching for div instead of div Id:
function checkContainer () {
if($("div").is(':visible'))){
createGrid();
}else {
setTimeout(checkContainer, 50);
}
}
Upvotes: 0
Reputation: 46900
I want to check is there any visible div element with JQuery
if ($("div:visible").length)
This will return true if at least 1 div is visible
Upvotes: 4
Reputation: 7504
If any div, I think that's enough :
if($('div')){console.log('present');}
Upvotes: 0