Skip to content

JavaScript Cheat Sheet

fahimc edited this page Mar 25, 2013 · 1 revision

##Getting a DOM Element

  1. Create an element and give it an ID.
  2. In a JS file use document.getElementById to obtain the DOM element.
//html
<div id="test"></div>

//javascript
var test = document.getElementById("test");

##Styling a DOM Element (Basic)

  1. Get the Element.
  2. Use the 'style' method to style your objects. Remember to provide a string value. Use camel case for attributes that are hyphenated.
var test = document.getElementById("test");
test.style.display ="block";
test.style.backgroundColor ="#f00";