To Lecture Notes

IT 238 -- Feb 23, 2026

Review Exercises

  1. Display this image of the Andromeda Galaxy on an HTML page. When the image is clicked, use JavaScript to add a border, a margin, and padding to the image.
  2. Start with this HTML body:
    <body>
        <h2>Ordered List Example</h1>
    </body>
    
    Use JavaScript to create and append this ordered list to the body:
    1. New York City
    2. Los Angeles
    3. Chicago
  3. What is the difference between the CSS properties display and visibility for an HTML element?

Project 2b

The jQuery JavaScript Library

Basic jQuery Syntax

Some jQuery Examples

JavaScript querySelector Method

The W3Schools jQuery Tutorial

Look at some of the examples in the jQuery Tutorial:
www.w3schools.com/jquery/default.asp.

Translate these jQuery function calls from jQuery into vanilla JavaScript. Also, write the JavaScript functions in arrow notation.

  1. Add an event handler for the window load event that displays "Hello, World!" in an alert box.
    $(function( ) {
        alert("Hello, World!");
    }
    
    or
    $(( ) => { 
        alert("Hello, World!"); 
    });
    
  2. Add an event handler to a button that displays "Hello, World!" in an alert box.
    $(function( ) {
        $("btn1").click(function( ) {
            alert("Hello, World!");
        });
    });
    
    or
    $(( ) => {
        $("bt1").click(( ) => {
            alert("Hello, World!");
        });
    });
    
  3. Try out the W3Schools double click event handler on this page:
         www.w3schools.com/jquery/jquery_events.asp
    $(function( ){
        $("p").dblclick(function( ){
            $(this).hide( );
        });
    });
    
    Translate it into vanilla JavaScript. Answer:
    function eventHandler(e) {
        var para = e.target;
        para.style.display = "none";
    }
    function init( ) {
        var para = document.querySelectorAll("p");
        for(let node of para)) {
            node.addEventListener("dblclick", 
                eventHandler);
        }
    }
    window.addEventListener("load", init);
    
    Here is the script written with anonymous functions using arrow notation:
    window.addEventListener("load", ( ) => {
        var para = document.querySelectorAll("p");
        for(let node of Array.from(para)) {
            node.addEventListener("dblclick", e => {
                var para = e.target;
                para.style.display = "none";
            });
        }
    });
    
  4. Also look the W3Schools examples for this other events:
    mouseenter  mouseleave  mousedown  
    mouseup  hover  focus  blur 
    
  5. The hover method combines the mousein and mouseout events. It accepts two event handlers:
    $("#p1").hover(function( ) {
        alert("Welcome! You entered p.");
    },
    function( ) {
        alert("Bye! You left p.");
    });
    
    Here is the Hover Example translated into JavaScript:
    // There is no hover event in vanilla JavaScript.
    // The mouseenter and mouseleave event handlers
    // must be implemented separately.
    window.addEventListener("load", ( ) => {
        var para1 = document.querySelector("p");
        para1.addEventListener("mouseenter", ( ) => {
            alert("Welcome! You entered p.");
        });
        para1.addEventListener("mouseleave", ( ) => {
            alert("Bye! You left p.");
        });
    });
    
  6. The on method attaches an event handler for a specified event. This on method is equivalent to the JavaScript method addEventHandler.  Here is an example that attaches a click event handler using the on method:
    $("p").on("click", function( ){
        $(this).hide( );
    }); 
    
  7. With the on method, more than one event handler can be attached using an object literal:
    $("p").on({
        mouseenter: function(){
            $(this).css("background-color", "lightgray");
        }, 
        mouseleave: function(){
            $(this).css("background-color", "lightblue");
        },
        click: function(){
            $(this).css("background-color", "yellow");
        }
    }); 
    
    Translate this event handler into vanilla JavaScript. Answer:
    window.addEventListener("load", ( ) => {
        var para = document.querySelector("p");
        para.addEventListener("mouseenter", ( ) => {
            para.style.backgroundColor = "lightgray";
        });
        para.addEventListener("mouseleave", ( ) => {
            para.style.backgroundColor = "lightblue";
        });
        para.addEventListener("mouseenter", ( ) => {
            para.style.backgroundColor = "lightgray";
        });
        para.addEventListener("click", ( ) => {
            para.style.backgroundColor = "yellow";
        });
    });