jquery check if div is visible on screen code example

Example 1: check if element is visible

.is(':visible')
//Selects all elements that are visible.

if($('#Div').is(':visible')){
	// add whatever code you want to run here.
}

$('#yourDiv:visible').callYourFunction();

Example 2: jquery how to know if element is visible

// Checks CSS content for display:[none|block], ignores visibility:[true|false]
$(element).is(":visible");

// The same works with hidden
$(element).is(":hidden");

Example 3: how to detect a section is visible in jquery

$.fn.isInViewport = function() {var elementTop = $(this).offset().top;var elementBottom = elementTop + $(this).outerHeight();var viewportTop = $(window).scrollTop();var viewportBottom = viewportTop + $(window).height();return elementBottom > viewportTop && elementTop < viewportBottom;};