This project demonstrates various JavaScript DOM manipulation and event handling techniques by adding interactive features to a Bootstrap-based webpage.
This is an educational project that transforms a static HTML page into an interactive experience using pure JavaScript. The project implements 9 different interactive features without modifying the original HTML file.
exo_events.html- The original HTML page (do not modify)script.js- JavaScript file containing all interactive featuresREADME.md- This documentation file
- Clone this repository or download the files
- Open
exo_events.htmlin a web browser - Open browser developer tools (F12) to see console outputs
- Test the various interactive features listed below
- Action: Click on the footer area
- Result: Console displays "click number X" (starting from 1, incrementing with each click)
- Implementation: Uses
addEventListener('click')with a counter variable
- Action: Click the hamburger menu button (three lines) in the top-right navbar
- Result: Toggles the visibility of the navigation header
- Implementation: Uses
classList.toggle('collapse')on the navbarHeader element
- Action: Click the "Edit" button on the first card (HTML card)
- Result: Card text turns red permanently (until page reload)
- Implementation: Sets
style.color = 'red'on the card text
- Action: Click the "Edit" button on the second card (CSS card)
- Result: Card text toggles between green and normal color
- Implementation: Uses conditional logic to toggle
style.colorbetween 'green' and ''
- Action: Double-click on the navbar area
- Result: Toggles Bootstrap CSS on/off, dramatically changing page appearance
- Implementation: Toggles
disabledproperty on the Bootstrap CSS link
- Action: Hover over any "View" button on the cards
- Result: Card shrinks (text disappears, image becomes 20% size, buttons remain)
- Implementation: Uses
mouseenter/mouseleaveevents with style modifications
- Action: Click the gray "==>" button
- Result: Last card (bottom-right) moves to first position (top-left)
- Implementation: Uses
insertBefore()to reorder DOM elements
- Action: Click the blue "<===" button
- Result: First card moves to last position
- Implementation: Uses
preventDefault()andinsertBefore()with nextSibling
- Action: Focus on the "JS & Events" logo and press keys:
a- Page content moves to left (4 columns)y- Page content moves to center (4 columns with offset)p- Page content moves to right (4 columns with larger offset)b- Returns to normal layout
- Implementation: Uses
keypressevent with Bootstrap class manipulation
- Element Selection:
querySelector(),querySelectorAll(),getElementById() - Event Handling:
addEventListener()for various event types (click, dblclick, mouseenter, mouseleave, keypress) - Style Modification: Direct
styleproperty manipulation - Class Manipulation:
classList.toggle(),classList.add(),classList.remove() - DOM Structure:
insertBefore(),nextSibling
- DOM Ready: Wrapped all code in
DOMContentLoadedevent listener - Event Prevention: Used
preventDefault()to stop default link behavior - Loop Variables: Used
letinstead ofvarinforEachto avoid closure issues - Accessibility: Made logo
focusablewith tabindex for keyboard events
The page logs various actions to the browser console:
- Footer clicks with incremental counter
- Confirmation message when all features are loaded
This project demonstrates mastery of:
- DOM Navigation: Finding and selecting HTML elements
- Event Handling: Responding to user interactions
- DOM Manipulation: Modifying content, styles, and structure
- JavaScript Fundamentals: Variables, conditionals, loops, functions
- Bootstrap Integration: Working with CSS frameworks
This project uses standard JavaScript DOM methods and should work in all modern browsers. Requires:
- ES6+ support for
const/letdeclarations - Modern DOM API support
- Open browser developer tools to see console messages
- Try all interactive elements in different sequences
- Notice how some features interact with each other (e.g., card reordering affects hover behavior)
- Use the keyboard shortcuts while focused on the logo
JS_events/
├── exo_events.html # Main HTML file with Bootstrap styling
├── script.js # JavaScript implementation of all features
└── README.md # This documentation