Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 118 - 2625 PortGPt V2.1
P. 118

    Tech Fact

                                     A JavaScript function is a section of code created to carry out a
                                     certain task.

                      Let’s see another interesting example where we change the background colour on the click of a
                      button!

                      <html>
                      <head> <title> EVENT HANDLING </title>
                      <script>

                      function changeColor() {
                       document.body.style.background = 'red';
                      }

                      </script></head>
                      <body bgcolor="blue">
                      <p> WELCOME </p>
                      <input type="button" onclick="changeColor()" value="Red">
                      </body> </html>

                                 Let’s Back-uP

                         •  An event is defined as a change in an object's state.
                         •  The act of responding to events is known as event handling.

                         •  JavaScript uses event handlers to handle HTML events.
                         •   You can attach an event handler to an event to respond to it. This is a section of code that
                             executes when the event occurs.
                         •   Using an HTML attribute with the name of the event handler allows you to add an event
                             handler to an event connected to an HTML element.
                         •   A function specified in a script can be called by an event handler defined in HTML.

                      116   Premium Edition-VIII

| 113 114 115 116 117 118 119 120 121 122 123 |