Exercise 9: Check if Element is Visible
Problem Statement
Function `isVisible(el)` banao jo check kare ki element visible hai ya nahi.
Example: isVisible(divEl) => true/false
Sample Output:
isVisible(divEl) => true (if visible) isVisible(hiddenEl) => false (if hidden)
Solution
const isVisible = (el) => {
if (!el) return false;
const style = window.getComputedStyle(el);
return style.display !== "none" && style.visibility !== "hidden" && style.opacity !== "0";
};Explanation
Overall Goal:
- Element visible hai ya nahi check karna.
Real world:
- UI logic: visibility checks.
- Conditional rendering: visibility-based logic.