Skip to content

Fix typos in hero subtitle and card title#21

Open
Adir-html wants to merge 2 commits into
codewithsadee:masterfrom
Adir-html:master
Open

Fix typos in hero subtitle and card title#21
Adir-html wants to merge 2 commits into
codewithsadee:masterfrom
Adir-html:master

Conversation

@Adir-html
Copy link
Copy Markdown

@Adir-html Adir-html commented Mar 31, 2026

Fixed spelling for HTML.

This PR addresses an issue where the addEventOnElem utility function incorrectly handled the window object due to an unreliable check for the .length property.

The Problem:
The original code used if (elem.length > 1) to determine if the input was a collection of elements. However:

Window Object Trap: In browsers, window.length returns the number of iframes on the page. If a page has 0 or 1 iframes, the function worked by accident. If a page had 2+ iframes, the function would attempt to loop through them instead of attaching the event to the window itself, breaking features like scroll-based header animations.

Logic Flaw: Checking for .length > 1 is a "leaky" way to detect arrays or NodeLists.

The Fix:
I have refactored addEventOnElem to use more explicit type checking:

It now checks if the element is an instanceof NodeList or Array.isArray().

This ensures that collections are always looped through correctly, while single objects (like window or individual HTMLElements) are handled by the fallback else block.

Changes:

Updated addEventOnElem logic in script.js.

Verified that navbar toggles (NodeLists) and window scrolling (Object) both function correctly after the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant