Javascript
Script Tags
The second and fourth lines of HTML comments are from the days of dealing with old browsers that ignore the <script>-tag, and would otherwise try to print out what's within those tags.Functions
With Arguments
With No Arguments
With Returned Values
Anonymous Functions
Strings
Statements: Conditions
If-Else
For
For Through Properties of an Object
Forms
Running a function before submitting
Accessing form elements directly
Accessing form methods
Pre-written Functions
.length - Length of String or Number
.toString() - Convert number to string
Convert string to number
Concatenating a number to a string
Objects
Method vs. Property
object.method()
someObject.methodDoesThings() - Something happens when it's called (the method does something).object.property
someObject.propertyIsValue - You get (or set) this value when it's called (the property is something - a number, string, boolean, etc.)Initializing an Object
Adding and Defining Properties of an Object
Calling Methods of an Object
Object Check
It is a good idea to check whether the object exists in a given browser.Object Check to Exit a Function
This
Associative Arrays (a.k.a. Hashes)
The array associates each key with a value.For/in Statement
Go through all properties of the "person" object (i.e. go through all keys in the associative array "person")Popups
Events
Inline Event Registration
Traditional Event Registration
Traditional Event Registration - Multiple
Advanced Event Registration
Mouse Events
Onmouseover - hovering over element
Onmouseout - hovering off of element
Onmousedown - holding click down
Onmouseup - releasing click button
Onclick = onmousedown + onmouseup
Onmousemove
window.status
In browsers like Firefox, this is disabled by default.Offsets/Position
Getting and Setting Styles
Opacity
Javascript Property Reference Equivalents of CSS Properties
Examples
JS: document.getElementById("showyourid").style.backgroundColor = "#000000";
CSS: #showyourid {background-color:#000000;}
Conversion Table
| CSS Property | JavaScript Reference |
|---|---|
| background | background |
| background-attachment | backgroundAttachment |
| background-color | backgroundColor |
| background-image | backgroundImage |
| background-position | backgroundPosition |
| background-repeat | backgroundRepeat |
| border | border |
| border-bottom | borderBottom |
| border-bottom-color | borderBottomColor |
| border-bottom-style | borderBottomStyle |
| border-bottom-width | borderBottomWidth |
| border-color | borderColor |
| border-left | borderLeft |
| border-left-color | borderLeftColor |
| border-left-style | borderLeftStyle |
| border-left-width | borderLeftWidth |
| border-right | borderRight |
| border-right-color | borderRightColor |
| border-right-style | borderRightStyle |
| border-right-width | borderRightWidth |
| border-style | borderStyle |
| border-top | borderTop |
| border-top-color | borderTopColor |
| border-top-style | borderTopStyle |
| border-top-width | borderTopWidth |
| border-width | borderWidth |
| clear | clear |
| clip | clip |
| color | color |
| cursor | cursor |
| display | display |
| filter | filter |
| font | font |
| font-family | fontFamily |
| font-size | fontSize |
| font-variant | fontVariant |
| font-weight | fontWeight |
| height | height |
| left | left |
| letter-spacing | letterSpacing |
| line-height | lineHeight |
| list-style | listStyle |
| list-style-image | listStyleImage |
| list-style-position | listStylePosition |
| list-style-type | listStyleType |
| margin | margin |
| margin-bottom | marginBottom |
| margin-left | marginLeft |
| margin-right | marginRight |
| margin-top | marginTop |
| overflow | overflow |
| padding | padding |
| padding-bottom | paddingBottom |
| padding-left | paddingLeft |
| padding-right | paddingRight |
| padding-top | paddingTop |
| page-break-after | pageBreakAfter |
| page-break-before | pageBreakBefore |
| position | position |
| float | styleFloat |
| text-align | textAlign |
| text-decoration | textDecoration |
| text-decoration: blink | textDecorationBlink |
| text-decoration: line-through | textDecorationLineThrough |
| text-decoration: none | textDecorationNone |
| text-decoration: overline | textDecorationOverline |
| text-decoration: underline | textDecorationUnderline |
| text-indent | textIndent |
| text-transform | textTransform |
| top | top |
| vertical-align | verticalAlign |
| visibility | visibility |
| width | width |
| z-index | zIndex |