Cheat Sheet

JavaScript For Kids For Dummies Cheat Sheet

From JavaScript For Kids For Dummies

By Chris Minnick, Eva Holland

When you’re programming in JavaScript, you need to know how to convert CSS property names to JavaScript. An important part of JavaScript’s ability to perform useful functions in the browser is its ability to respond to events, including those listed here. Finally, some words cannot be used as JavaScript variables, functions, methods, loop labels, or object names; those reserved words are listed here.

Converting CSS Property Names to JavaScript

You can convert CSS property names to JavaScript. However, there are a few things you should remember if you plan on doing this. When changing styles with JavaScript, there are a couple simple rules:

  • If the CSS property is one word (such as height), it remains as it is.

  • If the CSS property is more than one word, separated by dashes, it gets converted to camelCase.

Here is a complete reference of the property name conversions from CSS to JavaScript.

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
float cssFloat
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
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

Web Browser Events in JavaScript

Web pages are much more than just static displays of text and graphics. JavaScript gives web pages interactivity and the ability to perform useful work. An important part of JavaScript’s ability to perform useful functions in the browser is its ability to respond to events.

Here is a list of common events that happen in web browsers that JavaScript can respond to.

Event Occurs When . . .
abort The loading of a file is aborted.
blur An element has gone out of focus. In other words, the element
is no longer the thing that the user is focusing on.
change An element’s value has changed since losing and regaining
focus.
click A mouse has been clicked on an element.
dbclick A mouse has been clicked twice on an element.
error A file failed to load.
focus An element has come into focus. In other words, the element is
what the user is currently focusing on.
input The value of an <input> or
<textarea> element is changed.
keydown A key is pressed down.
keyup A key is released after being pressed.
load A file and its attached files have finished loading.
mousedown A mouse button has been pressed down on an element.
mouseenter A mouse pointer is moved onto the element that has the listener
attached.
mouseleave A mouse pointer is moved off the element that has the listener
attached.
mousemove A mouse pointer is moved over an element.
mouseout A mouse pointer is moved off the element or one of its children
that has the listener attached.
mouseover A mouse pointer is moved onto the element or one of its
children that the listener is attached to.
mouseup A mouse button is released over an element.
mousewheel A wheel button of a mouse is rotated.
reset A form is reset.
resize The document has been resized.
scroll The document or an element has been scrolled.
select Text has been selected.
submit A form is submitted.

What Are JavaScript Reserved Words?

JavaScript has some reserved words you should know before you begin coding. The following table contains a list of JavaScript reserved words, which cannot be used as JavaScript variables, functions, methods, loop labels, or object names.

abstract boolean break
byte case catch
char class const
continue debugger default
delete do double
else enum export
extends false final
finally float for
function goto if
implements import in
instanceof int interface
long native new
null package private
protected public return
short static super
switch synchronized this
throw throws transient
true try typeof
var void volatile
while with