- Simple On-click: [PageSource]
- Javascript is introduced in a <script> section.
- As typical, this contains data and function declarations.
- Functions are called from onclick attributes.
- The value of the onclick is Javascript code.
- On-Click, again: [PageSource]
- Same effect as first one.
- Events are added in Javascript, not HTML. This method is
considered superior (or at least in style these days).
- There are
many
events.
- Handler can accept an
Event
object, which describes the event.
- Notice that the margin style on the bottom is added inline
rather than in the style. This code breaks without that.
- On-Click, once again: [PageSource]
- This one creates most of the page by dynamically creating
the HTML elements.
- The function addbox creates each of the interesting divs,
decorates it, and fills it.
- Note that addbox adds a method to the div object which it
creates. Note that it uses the fact that functions are closures
means they keep the values of the parameters sent to addbox.
- Also uses the fact that addEventListener can establish multiple
listeners on the same event. (On attributes cannot.)
- On-Click, yet again: [PageSource]
- This uses an event to build the document on page load.
- TextContent [PageSource]
- Just to show the use of text content.
- Notice that text content is not parsed as HTML, but shown
literally.
- The innerHTML attribute can be used to if you need to add HTML
content.
- Adjustable Text List [PageSource]
- This is an elaboration of the last one, which allows:
- Two-way movement through the list.
- Deletion of messages.
- Addition of messages.
- It was intended to demonstrate the use of a text input area,
but sort of grew out of proportion.
- The entry box is not seen unless it is in use. This is done
by setting the display style on its surrounding div to none.
- The click for entering a line changes that so the box appears.
- The line is actually inserted when you press enter using
a button press callback.
- Tabs [PageSource]
- The boxes are arranged using CSS.
- An outer div tabrow holding the three tabs, arranged
horizontally.
- An outer div contwrap below tabrow holding the three content boxes,
arranged on top of each other.
- Onclick events attached to each tabs expose its corresponding
content box by manipulating z-index.
- Document Write [Image IndexSource]
- This page has a lot of CSS, a little HTML and a little Javascript.
- The Javascript uses document.write to generate the
index for all 50 images, and replaces a lot of HTML.
- Inner HTML [Guessing GameSourceJavascript]
- A simple game you can play in your browser.
- This page has very little HTML (just the start page)
and a large Javascript file.
- The Javascript uses the innerHTML attribute to change
the page.
- The state of the game is recorded in Javascript variables.
- Timer events.
- [Ball DropSource]
- [Auto ColorsSource]
- [Slow Auto ColorsSource]
- [Someone's In ThereSource]