Documente Academic
Documente Profesional
Documente Cultură
Use window.onload to check for any features of HTML5 or to attach any event
handlers to the loaded elements.
This will prevent the need to write script tag at the end of body element.
If you use a variable that has not been declared, it returns 'undefined'
function f1(){
v1 = some expression; //gives undefined
}
If you use a variable that has been declared but not assigned any value, it returns
'null'.
function f1(){
var v1;
alert(v1); //gives null
}
When calling functions or using variables, copy the names of the function or
variable and paste them where you are using it.
(Typing the function and variable names again may cause spelling mistake).
function myFunction1(){
var myVar1;
.
.
.
alert(myvarl); //typing may cause case change and confusion in characters
like 1 or l.
}
myfucntionl(); //typing again may cause case, spelling and character changes.
To use getElementById function, copyt the text present in the id value of the
element in the html page.
<div id="myElem"><span>...</span></div>
var divElem = document.getElementById("myElem");
Use innerHTML property to get the contents of a element.
divElem.innerHTML returns '<span>...</span>'
Use outerHTML property to get the whole element itself;
divElem.outerHTML returns <div id="myElem"><span>...</span></div>
Use style property to access or change the style of an element.
divElem.style.property property can be width, height, font, background, color, ...
for sub-properties like margin-left, padding-right, text-color, access these
properties by removing - and capitalizing the first character or second word.
divElem.style.marginLeft, divElem.style.paddingRight, divElem.style.textColor
To write function, type function (keyword) then type both paranthesis (), then type
both flower brackets {}
function fnName(){}
bring the cursor back between the paranthesis, and start typing the names of the
parameters and separate them with comma ,
function fnName(param1, param2,..){}
put the cursor between the flower brackets and press enter twice.
function fnName(param1, param2,..){
}
Bring the cursor to the empty line, give a tab space and start typing new line of
code.
End the line of code with a ; (but it is not necessary)
function fnName(param1, param2,..){
var v1="abc"; var v2= 123;...
var v3= param1 (any operator) param2;
}
function fnName(param1, param2,..){
var v1="abc"
var v2=123
...
}