
Enter a search term above to see results...
Enter a search term above to see results...
Control element visibility with automatic display value restoration.
Shows hidden elements by restoring their natural display value.
CSS Analysis: By default,
show()
parses stylesheets and calculates CSS specificity to determine the natural display value. This handles elements with CSS-defined display properties that tag-based lookups miss. Setcalculate: false
for faster execution when you know elements use standard tag defaults.
$('selector').show()$('selector').show(options)
Name | Type | Description |
---|---|---|
calculate | boolean | Analyze stylesheets for accurate display calculation. When false , uses tag-based lookup. Defaults to true . |
Query object (for chaining).
// Show hidden elements$('.hidden').show();
// Elements get their natural display value$('div').show(); // display: block$('span').show(); // display: inline$('table').show(); // display: table
// Fast mode - uses tag-based lookup$('.many-elements').show({ calculate: false });
Hides elements by setting their display to ‘none’.
$('selector').hide()
Query object (for chaining).
// Hide visible elements$('.visible').hide();
// Hide multiple elements$('div, span').hide();
// Chain with other methods$('.item') .hide() .addClass('hidden') .attr('aria-hidden', 'true');
Toggles element visibility by checking their current display state and either showing or hiding them.
$('selector').toggle()$('selector').toggle(options)
Name | Type | Description |
---|---|---|
calculate | boolean | Analyze stylesheets for accurate display calculation when showing elements. When false , uses tag-based lookup. Defaults to true . |
Query object (for chaining).
// Toggle visibility of elements$('.item').toggle();
// Fast mode$('.item').toggle({ calculate: false });
// Interactive toggle on click$('.toggle-button').on('click', function() { $('.content').toggle();});
Gets the natural display value for elements (ignoring display: none
rules).
CSS Specificity Analysis: Parses stylesheets and calculates specificity to determine the display value that would apply if all
display: none
rules were ignored. Essential for proper element restoration.
$('selector').naturalDisplay()$('selector').naturalDisplay(options)
Name | Type | Description |
---|---|---|
calculate | boolean | Analyze stylesheets for accurate calculation. When false , uses tag-based lookup. Defaults to true . |
undefined
// Get natural display value of hidden elementconst hiddenDiv = $('.hidden-element');const naturalDisplay = hiddenDiv.naturalDisplay();console.log(naturalDisplay); // 'block'
// Element with CSS rules: .flex-container { display: flex; }const element = $('.flex-container.hidden');const display = element.naturalDisplay();console.log(display); // 'flex' (ignores 'none', finds highest specificity)
// Fast mode for simple casesconst displays = $('.elements').naturalDisplay({ calculate: false });console.log(displays); // ['block', 'inline', 'table'] - tag-based lookup
Checks if elements are visible by examining layout dimensions and visibility properties.
Note Checking element visibility requires multiple DOM APIs:
getBoundingClientRect()
for layout dimensions,getComputedStyle()
for visibility properties, and optional opacity checks. This method combines these checks with proper edge case handling.
$('selector').isVisible()$('selector').isVisible(options)
Name | Type | Description |
---|---|---|
includeOpacity | boolean | Also check that opacity > 0. Defaults to false . |
includeVisibility | boolean | Check for visibility: hidden and content-visibility: hidden . Defaults to true . |
boolean
- true
if ALL elements are visible, false
if ANY element is not visible, or undefined
for empty selection.
// Check if element has layout dimensionsif ($('#element').isVisible()) { console.log('Element is rendered');}
// Check visual visibility including opacityif ($('.fade-element').isVisible({ includeOpacity: true })) { console.log('Element is visually perceivable');}
// Skip visibility property checksconst hasLayout = $('.element').isVisible({ includeVisibility: false });
display: none
→ false
visibility: hidden
→ false
(default)opacity: 0
→ true
(unless includeOpacity: true
)width: 0; height: 0
→ false
Get the element that clips (crops) each element’s visual bounds based on overflow properties.
Note Positioned elements can be clipped by ancestors with
overflow
,clip-path
,mask
, orcontain
properties. This method traverses the DOM to find the nearest clipping ancestor, useful for positioning tooltips and overlays.
$('selector').clippingParent()
A new Query object containing the clipping parent elements.
// Find what element clips a positioned elementconst $tooltip = $('.tooltip');const $clipper = $tooltip.clippingParent();
// Check if element is clipped by its containerif ($clipper[0] !== document.documentElement) { console.log('Element is clipped by:', $clipper[0]);}
// Find scrollable container that clips contentconst $content = $('.overflow-content');const $scrollContainer = $content.clippingParent();
Clipping Detection: Returns
document.documentElement
when no clipping parent is found.
Get the offsetParent
of an element as reported by the Dom.
Simple Access This is a direct wrapper around the native
offsetParent
property this may not always be the positioning parent for fixed position elements.
$('selector').offsetParent()
A new Query object containing the offset parent elements.
// Quick access to offsetParentconst $offsetParent = $('#element').offsetParent();
// For simple positioning calculationsconst $element = $('#positioned-element');const $parent = $element.offsetParent();console.log('Positioned relative to:', $parent[0]);
Get the accurate positioning context for each element, considering modern CSS properties that create containing blocks.
Accurate Positioning This method finds the actual element that coordinates like
top
andleft
are relative to when positioning elements. UnlikeoffsetParent
, it accounts for stacking contexts created bytransform
,will-change
,filter
,perspective
,contain
, and other modern CSS properties.
$('selector').positioningParent()$('selector').positioningParent(options)
Name | Type | Description |
---|---|---|
calculate | boolean | Calculate positioning parent using modern CSS properties. When false , uses browser’s offsetParent . Defaults to true . |
A new Query object containing the positioning parent elements.
// Find accurate positioning context (recommended for positioning)const $absoluteEl = $('.absolute-positioned');const $positioningParent = $absoluteEl.positioningParent();
// Position element relative to its true positioning contextconst rect = $positioningParent[0].getBoundingClientRect();$absoluteEl.css({ top: rect.height / 2, left: rect.width / 2 });
// Handle fixed positioning with transformsconst $fixedEl = $('.fixed-positioned');const $context = $fixedEl.positioningParent(); // Finds transform/filter ancestors
// Fallback to simple offsetParent behaviorconst $offsetParent = $element.positioningParent({ calculate: false });
This method detects elements that create containing blocks through:
position: relative/absolute/fixed
transform
(any value except none
)filter
(any value except none
)perspective
(any value except none
)contain: paint/layout
will-change: transform/filter/perspective
container-type
)Get the nearest scrollable container for each element, useful for positioning overlays and handling scroll events.
Scroll Container Detection This method traverses the DOM to find the nearest ancestor with
overflow
properties that create scrollable containers. Returnswindow
when no scrollable ancestor is found, representing the root scroll container.
$('selector').scrollParent()$('selector').scrollParent(options)
Name | Type | Description |
---|---|---|
all | boolean | Return all scroll parents in the hierarchy instead of just the nearest one. Defaults to false . |
A new Query object containing the scroll parent element(s).
// Find nearest scrollable containerconst $tooltip = $('.tooltip');const $scrollContainer = $tooltip.scrollParent();
// Position tooltip within scrollable boundsif ($scrollContainer[0] !== window) { console.log('Element is scrolled by:', $scrollContainer[0]);}
// Get all scroll containers in the hierarchyconst $allScrollers = $('.deep-content').scrollParent({ all: true });$allScrollers.each(container => { console.log('Scroll container:', container);});
// Handle scroll events on the appropriate containerconst $element = $('.sticky-element');const $scroller = $element.scrollParent();$scroller.on('scroll', () => { // Update sticky element position});
This method detects scrollable containers through:
overflow: hidden/scroll/auto
overflow-x: hidden/scroll/auto
overflow-y: hidden/scroll/auto
Returns window
when no scrollable ancestor is found (elements scroll with the viewport).
all: true
When all: true
is specified:
window
as the final scroll container// Multiple elements with nested scroll containers$('.items').scrollParent({ all: true });// Returns: [inner-scroller, outer-scroller, window, other-scroller, window]
Checks if elements are within the viewport bounds. This method leverages the intersects()
method internally, inheriting all its configuration options.
$('selector').isInView()$('selector').isInView(options)
Name | Type | Description |
---|---|---|
threshold | number | Minimum percentage (0-1) visible. Defaults to 0 . |
fully | boolean | Element must be fully within viewport. Defaults to false . |
viewport | string|Element|Query | Viewport element to check against. Defaults to clipping parent. |
sides | string|Array | Which sides must intersect (‘all’ or specific sides). Defaults to 'all' . |
returnDetails | boolean | Whether to return detailed intersection data. Defaults to false . |
all | boolean | Whether all elements must be in view (true) or any element (false). Defaults to false . |
boolean
- true
if criteria are met, false
otherwise. When returnDetails: true
, returns detailed intersection data instead.
// Check if any part is visible in clipping parent (default)if ($('#element').isInView()) { console.log('Element is at least partially visible in container');}
// Check if element is fully within clipping parentif ($('#element').isInView({ fully: true })) { console.log('Element is completely visible in container');}
// Check if at least 50% is visibleif ($('#element').isInView({ threshold: 0.5 })) { console.log('At least half the element is visible');}
// Check against specific viewport elementif ($('#tooltip').isInView({ viewport: '#modal' })) { console.log('Tooltip is visible within modal bounds');}
// Check only specific sidesif ($('#element').isInView({ sides: ['top', 'bottom'] })) { console.log('Element intersects top or bottom of viewport');}
// Check that ALL elements in selection are visibleif ($('.items').isInView({ all: true })) { console.log('All items are at least partially visible');}
// Get detailed intersection informationconst details = $('#element').isInView({ returnDetails: true });console.log('Intersection ratio:', details.ratio);console.log('Intersection rect:', details.rect);
false
for empty selections (or null
when returnDetails: true
)true
if ANY element meets criteria (use all: true
to require all elements)fully: true
overrides any threshold settingviewport
parameterintersects()
methodreturnDetails: true
, returns detailed intersection data instead of boolean