Professional Documents
Culture Documents
www.w3school.com.cn
2014.10.3
JavaScript Array .................................................................................... 14
JavaScript constructor .............................................................................................................16
JavaScript length ..................................................................................................................... 18
JavaScript prototype ............................................................................................................... 19
JavaScript concat() .................................................................................................................. 20
JavaScript join() ....................................................................................................................... 22
JavaScript pop() .......................................................................................................................24
JavaScript push() ..................................................................................................................... 25
JavaScript reverse() ................................................................................................................. 26
JavaScript shift() ...................................................................................................................... 27
JavaScript slice() ...................................................................................................................... 28
JavaScript sort() .......................................................................................................................31
JavaScript splice() .................................................................................................................... 33
JavaScript toSource() ...............................................................................................................36
JavaScript toString() ................................................................................................................ 37
JavaScript toLocaleString() ...................................................................................................... 38
JavaScript unshift() ..................................................................................................................39
JavaScript valueOf() .................................................................................................................41
JavaScript .....................................................................................226
JavaScript decodeURI() ......................................................................................................... 228
JavaScript decodeURIComponent() ...................................................................................... 229
JavaScript encodeURI() ......................................................................................................... 230
JavaScript encodeURIComponent() ...................................................................................... 232
JavaScript escape() ................................................................................................................233
JavaScript eval() .....................................................................................................................234
JavaScript getClass() ..............................................................................................................236
JavaScript isFinite() ................................................................................................................237
JavaScript isNaN() ..................................................................................................................239
JavaScript Number() ..............................................................................................................240
JavaScript parseFloat() .......................................................................................................... 241
JavaScript parseInt() ..............................................................................................................244
JavaScript String() ..................................................................................................................245
JavaScript unescape() ............................................................................................................246
JavaScript Infinity .................................................................................................................. 247
JavaScript java ....................................................................................................................... 248
JavaScript NaN .......................................................................................................................249
JavaScript Packages ...............................................................................................................250
JavaScript undefined ............................................................................................................. 251
Window .........................................................................................................................252
HTML DOM closed ................................................................................................................ 255
HTML DOM defaultStatus ..................................................................................................... 256
HTML DOM innerheightinnerwidth ..................................................................................257
HTML DOM name ................................................................................................................. 257
HTML DOM opener ............................................................................................................... 258
HTML DOM outerheight ....................................................................................................... 259
HTML DOM outerwidth ........................................................................................................ 260
HTML DOM self ..................................................................................................................... 261
HTML DOM status ................................................................................................................. 262
HTML DOM top ..................................................................................................................... 263
HTML DOM alert() .................................................................................................................264
HTML DOM blur() ..................................................................................................................265
HTML DOM clearInterval() ....................................................................................................266
HTML DOM clearTimeout() ...................................................................................................267
HTML DOM close() ................................................................................................................ 268
HTML DOM confirm() ............................................................................................................269
HTML DOM createPopup() ....................................................................................................270
HTML DOM focus() ................................................................................................................271
HTML DOM moveBy() ........................................................................................................... 272
HTML DOM moveTo() ........................................................................................................... 273
HTML DOM open() ................................................................................................................274
HTML DOM print() ................................................................................................................ 276
HTML DOM prompt() ............................................................................................................ 277
HTML DOM resizeBy() ........................................................................................................... 278
HTML DOM resizeTo() ........................................................................................................... 279
HTML DOM scrollBy() ............................................................................................................280
HTML DOM scrollTo() ............................................................................................................ 282
HTML DOM setInterval() .......................................................................................................283
HTML DOM setTimeout() ......................................................................................................284
Navigator ......................................................................................................................285
HTML DOM appCodeName .................................................................................................. 287
HTML DOM appMinorVersion .............................................................................................. 288
HTML DOM appName ...........................................................................................................288
HTML DOM appVersion ........................................................................................................ 289
HTML DOM browserLanguage ..............................................................................................290
HTML DOM cookieEnabled ...................................................................................................290
HTML DOM cpuClass .............................................................................................................291
HTML DOM onLine ................................................................................................................292
HTML DOM platform .............................................................................................................292
HTML DOM systemLanguage ................................................................................................293
HTML DOM userAgent .......................................................................................................... 294
HTML DOM
HTML DOM Anchor ............................................................................................................... 340
HTML DOM Area ................................................................................................................... 342
HTML DOM Base ................................................................................................................... 343
HTML DOM Body .................................................................................................................. 343
HTML DOM Button ................................................................................................................344
HTML DOM Canvas ............................................................................................................... 345
HTML DOM Form .................................................................................................................. 346
HTML DOM Frame ................................................................................................................ 348
HTML DOM Frameset ........................................................................................................... 349
HTML DOM IFrame ............................................................................................................... 350
HTML DOM Image .................................................................................................................351
HTML DOM Button ................................................................................................................352
HTML DOM Checkbox ........................................................................................................... 353
HTML DOM FileUpload ......................................................................................................... 355
HTML DOM Hidden ............................................................................................................... 356
HTML DOM Password ........................................................................................................... 357
HTML DOM Radio ................................................................................................................. 359
HTML DOM Reset ..................................................................................................................360
HTML DOM Submit ............................................................................................................... 361
HTML DOM Text .................................................................................................................... 363
HTML DOM Link .................................................................................................................... 364
HTML DOM Meta .................................................................................................................. 365
HTML DOM Object ................................................................................................................368
HTML DOM Option ............................................................................................................... 369
HTML DOM Select .................................................................................................................370
HTML DOM Table .................................................................................................................. 372
HTML DOM TableCell ............................................................................................................ 391
HTML DOM TableRow ........................................................................................................... 398
HTML DOM Textarea .............................................................................................................404
onkeydown ............................................................................................................................728
onkeypress ............................................................................................................................ 731
onKeyUp ................................................................................................................................ 733
onload ................................................................................................................................... 735
onmousedown ...................................................................................................................... 737
onmousemove ...................................................................................................................... 740
onmouseout ..........................................................................................................................741
onmouseover ........................................................................................................................ 743
onreset .................................................................................................................................. 746
onresize ................................................................................................................................. 747
onselect ................................................................................................................................. 748
onsubmit ............................................................................................................................... 750
onunload ............................................................................................................................... 751
altKey .............................................................................................................................752
button ............................................................................................................................754
clientX ............................................................................................................................757
clientY ............................................................................................................................758
ctrlKey ............................................................................................................................760
metaKey ........................................................................................................................ 762
relatedTarget ................................................................................................................. 763
screenX ..........................................................................................................................765
screenY .......................................................................................................................... 766
shiftKey ..........................................................................................................................768
bubbles ..........................................................................................................................770
cancelable ..................................................................................................................... 771
currentTarget .................................................................................................................773
eventPhase ............................................................................................................................774
target ............................................................................................................................. 775
timeStamp .....................................................................................................................776
type ............................................................................................................................... 778
initEvent() .............................................................................................................................. 779
preventDefault() ....................................................................................................................780
stopPropagation() ................................................................................................................. 781
JavaScript Array
Array
Array
Array
new Array();
new Array(size);
new Array(element0, element1, ..., elementn);
Array() length 0
undefined
Array()
new new
Array
FF: Firefox, IE: Internet Explorer
FF
IE
constructor
index
input
length
prototype
Array
FF: Firefox, IE: Internet Explorer
FF
IE
concat()
join()
pop()
5.5
push()
5.5
reverse()
shift()
5.5
slice()
sort()
splice()
5.5
toSource()
toString()
toLocaleString()
unshift()
valueOf()
JavaScript constructor
constructor
object.constructor
1
constructor
<script type="text/javascript">
var test=new Array();
if (test.constructor==Array)
{
document.write("This is an Array");
}
if (test.constructor==Boolean)
{
document.write("This is a Boolean");
}
if (test.constructor==Date)
{
document.write("This is a Date");
}
if (test.constructor==String)
{
document.write("This is a String");
}
</script>
This is an Array
2
constructor
<script type="text/javascript">
function employee(name,job,born)
{
this.name=name;
this.job=job;
this.born=born;
}
var bill=new employee("Bill Gates","Engineer",1985);
document.write(bill.constructor);
</script>
JavaScript length
length
arrayObject.length
length 1
0 length
length Array()
length
length
undefined
length
<script type="text/javascript">
var arr = new Array(3)
arr[0] = "John"
arr[1] = "Andy"
arr[2] = "Wendy"
Original length: 3
New length: 5
JavaScript prototype
prototype
object.prototype.name=value
prototype
<script type="text/javascript">
function employee(name,job,born)
{
this.name=name;
this.job=job;
this.born=born;
}
var bill=new employee("Bill Gates","Engineer",1985);
employee.prototype.salary=null;
bill.salary=20000;
document.write(bill.salary);
</script>
20000
JavaScript concat()
concat()
arrayObject.concat(arrayX,arrayX,......,arrayX)
arrayX
arrayX arrayObject
concat()
1
concat() a
<script type="text/javascript">
var a = [1,2,3];
document.write(a.concat(4,5));
</script>
1,2,3,4,5
2
concat()
<script type="text/javascript">
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
var arr2 = new Array(3)
arr2[0] = "James"
arr2[1] = "Adrew"
arr2[2] = "Martin"
document.write(arr.concat(arr2))
</script>
George,John,Thomas,James,Adrew,Martin
3
concat()
<script type="text/javascript">
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
George,John,Thomas,James,Adrew,Martin,William,Franklin
JavaScript join()
join()
arrayObject.join(separator)
separator
arrayObject
separator
<script type="text/javascript">
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr.join())
</script>
George,John,Thomas
2
<script type="text/javascript">
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr.join("."))
</script>
George.John.Thomas
JavaScript pop()
pop()
arrayObject.pop()
arrayObject
pop() arrayObject 1
pop() undefined
<script type="text/javascript">
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr)
document.write("<br />")
document.write(arr.pop())
document.write("<br />")
document.write(arr)
</script>
George,John,Thomas
Thomas
George,John
JavaScript push()
push()
arrayObject.push(newelement1,newelement2,....,newelementX)
newelement1
newelement2
newelementX
unshift()
<script type="text/javascript">
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr + "<br />")
document.write(arr.push("James") + "<br />")
document.write(arr)
</script>
George,John,Thomas
4
George,John,Thomas,James
JavaScript reverse()
reverse()
arrayObject.reverse()
<script type="text/javascript">
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr + "<br />")
document.write(arr.reverse())
</script>
George,John,Thomas
Thomas,John,George
JavaScript shift()
shift()
arrayObject.shift()
shift() undefined
arrayObject
pop()
<script type="text/javascript">
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr + "<br />")
document.write(arr.shift() + "<br />")
document.write(arr)
</script>
George,John,Thomas
George
John,Thomas
JavaScript slice()
slice()
arrayObject.slice(start,end)
start
-1 -2
end
start
Array.splice()
<script type="text/javascript">
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr + "<br />")
George,John,Thomas
John,Thomas
George,John,Thomas
2
<script type="text/javascript">
var arr = new Array(6)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
arr[3] = "James"
arr[4] = "Adrew"
arr[5] = "Martin"
document.write(arr + "<br />")
document.write(arr.slice(2,4) + "<br />")
document.write(arr)
</script>
George,John,Thomas,James,Adrew,Martin
Thomas,James
George,John,Thomas,James,Adrew,Martin
JavaScript sort()
sort()
arrayObject.sort(sortby)
sortby
a b
a b a b 0
a b 0
a b 0
<script type="text/javascript">
var arr = new Array(6)
arr[0]
arr[1]
arr[2]
arr[3]
arr[4]
arr[5]
=
=
=
=
=
=
"George"
"John"
"Thomas"
"James"
"Adrew"
"Martin"
George,John,Thomas,James,Adrew,Martin
Adrew,George,James,John,Martin,Thomas
2
<script type="text/javascript">
var arr = new Array(6)
arr[0] = "10"
arr[1] = "5"
arr[2] = "40"
arr[3] = "25"
arr[4] = "1000"
arr[5] = "1"
document.write(arr + "<br />")
document.write(arr.sort())
</script>
10,5,40,25,1000,1
1,10,1000,25,40,5
<script type="text/javascript">
function sortNumber(a,b)
{
return a - b
}
var arr = new Array(6)
arr[0] = "10"
arr[1] = "5"
arr[2] = "40"
arr[3] = "25"
arr[4] = "1000"
arr[5] = "1"
document.write(arr + "<br />")
document.write(arr.sort(sortNumber))
</script>
10,5,40,25,1000,1
1,5,10,25,40,1000
JavaScript splice()
splice() //
arrayObject.splice(index,howmany,item1,.....,itemX)
index
howmany
Array
splice() index
arrayObject
JavaScript
1.2
splice()
<script type="text/javascript">
var arr = new Array(6)
arr[0] = "George"
arr[1]
arr[2]
arr[3]
arr[4]
arr[5]
=
=
=
=
=
"John"
"Thomas"
"James"
"Adrew"
"Martin"
George,John,Thomas,James,Adrew,Martin
George,John,William,Thomas,James,Adrew,Martin
2
index 2
<script type="text/javascript">
var arr = new Array(6)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
arr[3] = "James"
arr[4] = "Adrew"
arr[5] = "Martin"
document.write(arr + "<br />")
arr.splice(2,1,"William")
document.write(arr)
</script>
George,John,Thomas,James,Adrew,Martin
George,John,William,James,Adrew,Martin
3
<script type="text/javascript">
var arr = new Array(6)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
arr[3] = "James"
arr[4] = "Adrew"
arr[5] = "Martin"
document.write(arr + "<br />")
arr.splice(2,3,"William")
document.write(arr)
</script>
George,John,Thomas,James,Adrew,Martin
George,John,William,Martin
JavaScript toSource()
toSource()
Array
toSource() JavaScript
object.toSource()
toSource()
<script type="text/javascript">
function employee(name,job,born)
{
this.name=name;
this.job=job;
this.born=born;
}
var bill=new employee("Bill Gates","Engineer",1985);
document.write(bill.toSource());
</script>
JavaScript toString()
toString()
arrayObject.toString()
arrayObject join()
JavaScript
<script type="text/javascript">
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr.toString())
</script>
George,John,Thomas
JavaScript toLocaleString()
arrayObject.toLocaleString()
arrayObject
toLocaleString()
<script type="text/javascript">
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr.toLocaleString())
</script>
JavaScript unshift()
unshift()
arrayObject.unshift(newelement1,newelement2,....,newelementX)
newelement1
newelement2
newelementX
arrayObject
unshift() arrayObject
0
1
unshift()
<script type="text/javascript">
var arr = new Array()
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr + "<br />")
document.write(arr.unshift("William") + "<br />")
document.write(arr)
</script>
George,John,Thomas
4
William,George,John,Thomas
JavaScript valueOf()
valueOf() Array
Array
valueOf() JavaScript
arrayObject.valueOf()
JavaScript Boolean
Boolean
Boolean "true" "false"
Boolean
new Boolean(value); //
Boolean(value);
//
value
newBoolean()
Boolean
newBoolean()
Boolean
FF: Firefox, IE: Internet Explorer
FF
IE
constructor
Boolean
prototype
Boolean
FF: Firefox, IE: Internet Explorer
FF
IE
toSource()
toString()
valueOf()
Boolean
Boolean
JavaScript Boolean
Boolean toString()
toString() JavaScript
JavaScript Boolean
toString()
JavaScript
ECMAScript
class ECMAScript
JavaScript constructor
constructor Boolean
object.constructor
constructor
<script type="text/javascript">
var test=new Boolean();
if (test.constructor==Array)
{
document.write("This is an Array");
}
if (test.constructor==Boolean)
{
document.write("This is a Boolean");
}
if (test.constructor==Date)
{
document.write("This is a Date");
}
if (test.constructor==String)
{
document.write("This is a String");
}
</script>
This is a Boolean
JavaScript prototype
prototype
object.prototype.name=value
prototype
<script type="text/javascript">
function employee(name,job,born)
{
this.name=name;
this.job=job;
this.born=born;
}
var bill=new employee("Bill Gates","Engineer",1985);
employee.prototype.salary=null;
bill.salary=20000;
document.write(bill.salary);
</script>
20000
JavaScript toSource()
toSource()
object.toSource()
Internet Explorer
toSource()
<script type="text/javascript">
function employee(name,job,born)
{
this.name=name;
this.job=job;
this.born=born;
}
var bill=new employee("Bill Gates","Engineer",1985);
document.write(bill.toSource());
</script>
JavaScript toString()
toString()
booleanObject.toString()
Boolean TypeError
Boolean
Boolean
<script type="text/javascript">
var boo = new Boolean(true)
document.write(boo.toString())
</script>
true
JavaScript valueOf()
valueOf() Boolean
booleanObject.valueOf()
booleanObject
Boolean TypeError
Boolean valueOf()
<script type="text/javascript">
var boo = new Boolean(false)
document.write(boo.valueOf())
</script>
false
JavaScript Date
Date
Date
Date
var myDate=new Date()
Date
Date
FF: Firefox, IE: Internet Explorer
FF
IE
constructor
Date
prototype
Date
FF: Firefox, IE: Internet Explorer
FF
IE
Date()
getDate()
Date (1 ~ 31)
getDay()
Date (0 ~ 6)
getMonth()
Date (0 ~ 11)
getFullYear()
Date
getYear()
getFullYear()
getHours()
Date (0 ~ 23)
getMinutes()
Date (0 ~ 59)
getSeconds()
Date (0 ~ 59)
getMilliseconds()
Date (0 ~ 999)
getTime()
1970 1 1
getTimezoneOffset()
(GMT)
getUTCDate()
Date (1 ~ 31)
getUTCDay()
Date (0 ~ 6)
getUTCMonth()
Date (0 ~ 11)
getUTCFullYear()
Date
getUTCHours()
Date (0 ~ 23)
getUTCMinutes()
Date (0 ~ 59)
getUTCSeconds()
Date (0 ~ 59)
getUTCMilliseconds()
Date (0 ~ 999)
parse()
1970 1 1
setDate()
Date (1 ~ 31)
setMonth()
Date (0 ~ 11)
setFullYear()
Date
setYear()
setFullYear()
setHours()
Date (0 ~ 23)
setMinutes()
Date (0 ~ 59)
setSeconds()
Date (0 ~ 59)
setMilliseconds()
Date (0 ~ 999)
setTime()
Date
setUTCDate()
Date (1 ~ 31)
setUTCMonth()
Date (0 ~ 11)
setUTCFullYear()
Date
setUTCHours()
Date (0 ~ 23)
setUTCMinutes()
Date (0 ~ 59)
setUTCSeconds()
Date (0 ~ 59)
setUTCMilliseconds()
Date (0 ~ 999)
toSource()
toString()
Date
toTimeString()
Date
toDateString()
Date
toGMTString()
toUTCString()
toUTCString()
Date
toLocaleString()
Date
toLocaleTimeString()
Date
toLocaleDateString()
Date
UTC()
1970 1 1
valueOf()
Date
JavaScript constructor
constructor Date
object.constructor
constructor
<script type="text/javascript">
var test=new Date();
if (test.constructor==Array)
{
document.write("This is an Array");
}
if (test.constructor==Boolean)
{
document.write("This is a Boolean");
}
if (test.constructor==Date)
{
document.write("This is a Date");
}
if (test.constructor==String)
{
document.write("This is a String");
}
</script>
This is a Date
JavaScript prototype
prototype
object.prototype.name=value
prototype
<script type="text/javascript">
function employee(name,job,born)
{
this.name=name;
this.job=job;
this.born=born;
}
var bill=new employee("Bill Gates","Engineer",1985);
employee.prototype.salary=null;
bill.salary=20000;
document.write(bill.salary);
</script>
20000
JavaScript Date()
Date()
Date()
<script type="text/javascript">
document.write(Date())
</script>
JavaScript Date()
getDate()
dateObject.getDate()
dateObject 1 ~ 31
Date
<script type="text/javascript">
var d = new Date()
document.write(d.getDate())
</script>
10
2
<script type="text/javascript">
var birthday = new Date("July 21, 1983 01:15:00")
document.write(birthday.getDate())
</script>
21
JavaScript getDay()
getDay()
dateObject.getDay()
dateObject 0 6
Date
<script type="text/javascript">
var d=new Date()
document.write(d.getDay())
</script>
4
2
<script type="text/javascript">
var d=new Date()
var weekday=new Array(7)
weekday[0]="Sunday"
weekday[1]="Monday"
weekday[2]="Tuesday"
weekday[3]="Wednesday"
weekday[4]="Thursday"
weekday[5]="Friday"
weekday[6]="Saturday"
document.write("Today it is " + weekday[d.getDay()])
</script>
Today it is Thursday
JavaScript getMonth()
getMonth()
dateObject.getMonth()
dateObject 0 11
Date
<script type="text/javascript">
var d=new Date()
document.write(d.getMonth())
</script>
9
2
<script type="text/javascript">
var d=new Date()
var month=new Array(12)
month[0]="January"
month[1]="February"
month[2]="March"
month[3]="April"
month[4]="May"
month[5]="June"
month[6]="July"
month[7]="August"
month[8]="September"
month[9]="October"
month[10]="November"
month[11]="December"
document.write("The month is " + month[d.getMonth()])
</script>
JavaScript getFullYear()
getFullYear() 4
dateObject.getFullYear()
dateObject
Date
<script type="text/javascript">
var d = new Date()
document.write(d.getFullYear())
</script>
2013
2
<script type="text/javascript">
var born = new Date("July 21, 1983 01:15:00")
document.write("I was born in " + born.getFullYear())
</script>
JavaScript getYear()
getYear()
dateObject.getYear()
Date
<script type="text/javascript">
var d = new Date()
document.write(d.getYear())
</script>
113
2
<script type="text/javascript">
var born = new Date("July 21, 1983 01:15:00")
document.write("I was born in " + born.getYear())
</script>
I was born in 83
JavaScript getHours()
getHours()
dateObject.getHours()
dateObject 0 23 11
getHours()
10
Date
<script type="text/javascript">
var d = new Date()
document.write(d.getHours())
</script>
19
2
<script type="text/javascript">
var born = new Date("July 21, 1983 01:15:00")
document.write(born.getHours())
</script>
JavaScript getMinutes()
getMinutes()
dateObject.getMinutes()
dateObject 0 ~ 59
getMinutes()
10
Date
<script type="text/javascript">
var d = new Date()
document.write(d.getMinutes())
</script>
50
2
<script type="text/javascript">
var born = new Date("July 21, 1983 01:15:00")
document.write(born.getMinutes())
</script>
15
JavaScript getSeconds()
getSeconds()
dateObject.getSeconds()
dateObject 0 ~ 59
getSeconds()
10
Date
<script type="text/javascript">
var d = new Date()
document.write(d.getSeconds())
</script>
8
2
<script type="text/javascript">
var Birthday = new Date("July 21, 1983 01:15:00")
document.write(Birthday.getSeconds())
</script>
JavaScript getMilliseconds()
getMilliseconds()
dateObject.getMilliseconds()
dateObject 0 ~ 999
getMilliseconds()
100 10
Date
<script type="text/javascript">
var d = new Date()
document.write(d.getMilliseconds())
</script>
120
2
<script type="text/javascript">
var born = new Date("July 21, 1983 01:15:00")
document.write(born.getMilliseconds())
</script>
JavaScript getTime()
getTime() 1970 1 1
dateObject.getTime()
dateObject 1970 1 1 GMT
Date
1
1970/01/01
<script type="text/javascript">
var d = new Date()
document.write(d.getTime() + " milliseconds since 1970/01/01")
</script>
It's been: 43.804103077562154 years since 1970/01/01!
JavaScript getTimezoneOffset()
getTimezoneOffset()
dateObject.getTimezoneOffset()
GMT
Date
1
GMT
<script type="text/javascript">
-480
2
GMT +/-
<script type="text/javascript">
var d = new Date()
var gmtHours = d.getTimezoneOffset()/60
document.write("The local time zone is: GMT " + gmtHours)
</script>
JavaScript getUTCDate()
getUTCDate() (UTC)
dateObject.getUTCDate()
dateObject 1 ~ 31
Date
(UTC)
1
UTC
<script type="text/javascript">
var d = new Date()
document.write(d.getUTCDate())
</script>
10
2
UTC
<script type="text/javascript">
var birthday = new Date("July 21, 1983 01:15:00")
document.write(birthday.getUTCDate())
</script>
21
JavaScript getUTCDay()
getUTCDay()
dateObject.getUTCDay()
dateObject 0 ~ 6
Date
(UTC)
1
UTC
<script type="text/javascript">
var d=new Date()
document.write(d.getUTCDay())
</script>
4
2
<script type="text/javascript">
var d=new Date()
var weekday=new Array(7)
weekday[0]="Sunday"
weekday[1]="Monday"
weekday[2]="Tuesday"
weekday[3]="Wednesday"
weekday[4]="Thursday"
weekday[5]="Friday"
weekday[6]="Saturday"
document.write("Today it is " + weekday[d.getUTCDay()])
</script>
Today it is Thursday
JavaScript getUTCMonth()
getUTCMonth() UTC
dateObject.getUTCMonth()
dateObject 0 ~ 11
Date 1 0
Date
(UTC)
<script type="text/javascript">
var d=new Date()
document.write(d.getUTCMonth())
</script>
9
2
<script type="text/javascript">
var d=new Date()
var month=new Array(12)
month[0]="January"
month[1]="February"
month[2]="March"
month[3]="April"
month[4]="May"
month[5]="June"
month[6]="July"
month[7]="August"
month[8]="September"
month[9]="October"
month[10]="November"
month[11]="December"
document.write("The month is " + month[d.getUTCMonth()])
</script>
JavaScript getUTCFullYear()
getUTCFullYear() (UTC)
dateObject.getUTCFullYear()
dateObject
Date
(UTC)
1
In this example we get the current year and print it:
<script type="text/javascript">
var d = new Date()
document.write(d.getUTCFullYear())
</script>
2013
2
Here we will extract the year out of the specific date:
<script type="text/javascript">
var born = new Date("July 21, 1983 01:15:00")
document.write("I was born in " + born.getUTCFullYear())
</script>
JavaScript getUTCHours()
getUTCHours() (UTC)
dateObject.getUTCHours()
dateObject 0 ~ 23 11
getUTCHours()
10
Date
(UTC)
1
UTC
<script type="text/javascript">
var d = new Date()
document.write(d.getUTCHours())
</script>
12
2
UTC
<script type="text/javascript">
var born = new Date("July 21, 1983 01:15:00")
document.write(born.getUTCHours())
</script>
17
JavaScript getUTCMinutes()
getUTCMinutes() (UTC)
dateObject.getUTCMinutes()
dateObject 0 ~ 59
getUTCMinutes()
10
Date
(UTC)
1
UTC
<script type="text/javascript">
var d = new Date()
document.write(d.getUTCMinutes())
</script>
2
UTC
<script type="text/javascript">
var born = new Date("July 21, 1983 01:15:00")
document.write(born.getUTCMinutes())
</script>
15
JavaScript getUTCSeconds()
getUTCSeconds()
dateObject.getUTCSeconds()
dateObject 0 ~ 59
getUTCSeconds()
10
Date
(UTC)
1
UTC
<script type="text/javascript">
var d = new Date()
document.write(d.getUTCSeconds())
</script>
24
2
UTC
<script type="text/javascript">
var Birthday = new Date("July 21, 1983 01:15:00")
document.write(Birthday.getUTCSeconds())
</script>
JavaScript getUTCMilliseconds()
getUTCMilliseconds() (UTC)
dateObject.getUTCMilliseconds()
dateObject 0 ~ 999
getUTCMilliseconds()
100 10
Date
(UTC)
1
UTC
<script type="text/javascript">
var d = new Date()
document.write(d.getUTCMilliseconds())
</script>
546
2
UTC
<script type="text/javascript">
var born = new Date("July 21, 1983 01:15:00")
document.write(born.getUTCMilliseconds())
</script>
0
1
JavaScript parse()
parse() 1970/1/1
Date.parse(datestring)
datestring
1970/1/1 GMT
Date Date.parse()
dateobject.parse()
Date.parse() Date
1
1970/01/01 2005/07/08
<script type="text/javascript">
var d = Date.parse("Jul 8, 2005")
document.write(d)
</script>
1120752000000
2
<script type="text/javascript">
var minutes = 1000 * 60
var hours = minutes * 60
var days = hours * 24
var years = days * 365
var t = Date.parse("Jul 8, 2005")
var y = t/years
document.write("It's been: " + y + " years from 1970/01/01")
document.write(" to 2005/07/08!")
</script>
JavaScript setDate()
setDate()
dateObject.setDate(day)
day
1 ~ 31
ECMAScript
Date
setDate() 15
<script type="text/javascript">
var d = new Date()
d.setDate(15)
document.write(d)
</script>
JavaScript setMonth()
setMonth()
dateObject.setMonth(month,day)
month
0 ~ 11
day
1 ~ 31
EMCAScript
ECMAScript
Date
1
setMonth() d 0
<script type="text/javascript">
var d=new Date()
d.setMonth(0)
document.write(d)
</script>
Thu Jan 10 2013 20:08:07 GMT+0800 ()
2
setMonth() d 0
20
<script type="text/javascript">
var d=new Date()
d.setMonth(0,20)
document.write(d)
</script>
JavaScript setFullYear()
setFullYear()
dateObject.setFullYear(year,month,day)
year
month
0 ~ 11
day
1 ~ 31
Date
1
setFullYear() 1992
<script type="text/javascript">
var d = new Date()
d.setFullYear(1992)
document.write(d)
</script>
JavaScript setYear()
setYear()
dateObject.setYear(year)
year
ECMAScript
setYear() 1891
<script type="text/javascript">
var d = new Date()
d.setYear(1891)
document.write(d)
</script>
JavaScript setHours()
setHours()
dateObject.setHours(hour,min,sec,millisec)
hour
0 ~ 23 11
min
0 ~ 59 EMCAScript
sec
0 ~ 59 EMCAScript
millisec
0 ~ 999 EMCAScript
ECMAScript
JavaScript
0
Date
1
setHours() 15
<script type="text/javascript">
var d = new Date()
d.setHours(15)
document.write(d)
</script>
JavaScript setMinutes()
setMinutes()
dateObject.setMinutes(min,sec,millisec)
min
0 ~ 59
sec
0 ~ 59 EMCAScript
millisec
0 ~ 999 EMCAScript
ECMAScript
JavaScript
0
Date
setMinutes() 01
<script type="text/javascript">
var d = new Date()
d.setMinutes(1)
document.write(d)
</script>
JavaScript setSeconds()
dateObject.setSeconds(sec,millisec)
sec
0 ~ 59
millisec
0 ~ 999 EMCAScript
ECMAScript
JavaScript
0
Date
setSeconds() 01
<script type="text/javascript">
var d = new Date()
d.setSeconds(1)
document.write(d)
</script>
Thu Oct 10 2013 20:15:01 GMT+0800 ()
JavaScript setMilliseconds()
setMilliseconds()
dateObject.setMilliseconds(millisec)
millisec
dateObject 0 ~ 999
JavaScript
0
Date
setMilliseconds() 001
<script type="text/javascript">
var d = new Date()
d.setMilliseconds(1)
document.write(d)
</script>
JavaScript setTime()
setTime() Date
dateObject.setTime(millisec)
millisec
GMT 1970 1 1
Date() Date.UTC()
Date.parse()
millisec ECMAScript
Date
1
1970/01/01 77771564221
<script type="text/javascript">
JavaScript setUTCDate()
setUTCDate() (UTC)
dateObject.setUTCDate(day)
day
dateObject 1 ~ 31
Date
(UTC)
setUTCDate() 15
<script type="text/javascript">
var d = new Date()
d.setUTCDate(15)
document.write(d)
</script>
JavaScript setUTCMonth()
setUTCMonth() (UTC)
dateObject.setUTCMonth(month,day)
month
dateObject
0 ~ 11
day
1 ~ 31 dateObject
Date
(UTC)
1
setUTCMonth() 0
<script type="text/javascript">
var d=new Date()
d.setUTCMonth(0)
document.write(d)
</script>
document.write(d)
</script>
JavaScript setUTCFullYear()
setUTCFullYear() (UTC)
dateObject.setUTCFullYear(year,month,day)
year
dateObject
1999 99
month
dateObject
0 ~ 11
day
dateObject
1 ~ 31
Date
(UTC)
1
setUTCFullYear() 1992
<script type="text/javascript">
var d = new Date()
d.setUTCFullYear(1992)
document.write(d)
</script>
JavaScript setUTCHours()
setUTCHours() (UTC) 0 - 23
dateObject.setUTCHours(hour,min,sec,millisec)
hour
dateObject
0 ~ 23
min
dateObject
0 ~ 59
sec
dateObject
0 ~ 59
millisec
dateObject
1 ~ 999
Date
(UTC)
1
setUTCHours() UTC 23
<script type="text/javascript">
JavaScript setUTCMinutes()
setUTCMinutes() (UTC)
dateObject.setUTCMinutes(min,sec,millisec)
min
dateObject
0 ~ 59
sec
dateObject
0 ~ 59
millisec
dateObject
0 ~ 999
JavaScript
0
Date
(UTC)
setUTCMinutes() 01
<script type="text/javascript">
var d = new Date()
d.setUTCMinutes(1)
document.write(d)
</script>
JavaScript setUTCSeconds()
setUTCSeconds() (UTC)
dateObject.setUTCSeconds(sec,millisec)
sec
dateObject
0 ~ 59
millisec
dateObject
0 ~ 999
JavaScript
0
Date
(UTC)
setUTCSeconds() 01
<script type="text/javascript">
var d = new Date()
d.setUTCSeconds(1)
document.write(d)
</script>
JavaScript setUTCMilliseconds()
setUTCMilliseconds() (UTC)
dateObject.setUTCMilliseconds(millisec)
millisec
dateObject
0 ~ 999
JavaScript
0
Date
(UTC)
setUTCMilliseconds() 001
<script type="text/javascript">
JavaScript toSource()
toSource()
object.toSource()
Internet Explorer
toSource()
<script type="text/javascript">
function employee(name,job,born)
{
this.name=name;
this.job=job;
this.born=born;
}
var bill=new employee("Bill Gates","Engineer",1985);
document.write(bill.toSource());
</script>
JavaScript toString()
toString() Date
dateObject.toString()
dateObject
<script type="text/javascript">
var d = new Date()
document.write (d.toString())
</script>
JavaScript toTimeString()
toTimeString() Date
dateObject.toTimeString()
dateObject
JavaScript toDateString()
toDateString() Date
dateObject.toDateString()
dateObject
JavaScript toGMTString()
dateObject.toGMTString()
dateObject GMT
toUTCString()
1
GMT
<script type="text/javascript">
var d = new Date()
document.write (d.toGMTString())
</script>
<script type="text/javascript">
var born = new Date("July 21, 1983 01:15:00")
document.write(born.toGMTString())
</script>
JavaScript toUTCString()
dateObject.toUTCString()
dateObject
1
toUTCString() UTC
<script type="text/javascript">
var d = new Date()
document.write (d.toUTCString())
</script>
Thu, 10 Oct 2013 12:29:20 GMT
2
UTC
<script type="text/javascript">
var born = new Date("July 21, 1983 01:15:00")
document.write(born.toUTCString())
</script>
JavaScript toLocaleString()
toLocaleString() Date
dateObject.toLocaleString()
dateObject
<script type="text/javascript">
var d = new Date()
document.write(d.toLocaleString())
</script>
2013 10 10 8:29:53
2
<script type="text/javascript">
var born = new Date("July 21, 1983 01:15:00")
document.write(born.toLocaleString())
</script>
1983 7 21 1:15:00
JavaScript toLocaleTimeString()
toLocaleTimeString() Date
dateObject.toLocaleTimeString()
dateObject
JavaScript toLocaleDateString()
toLocaleDateString() Date
dateObject.toLocaleDateString()
dateObject
JavaScript UTC()
UTC() 1970 1 1
Date.UTC(year,month,day,hours,minutes,seconds,ms)
year
month
0 ~ 11
day
1 ~ 31
hours
0 ~ 23
minutes
0 ~ 59
seconds
0 ~ 59
ms
0 ~ 999
GMT 1970 1 1
Date.UTC() Date()
Date
Date.UTC() UTC GMT UTC
Date() Date.setTime()
1
1970/01/01 2005/07/08
<script type="text/javascript">
var d = Date.UTC(2005,7,8)
document.write(d)
</script>
1123459200000
2
<script type="text/javascript">
var minutes = 1000 * 60
JavaScript valueOf()
valueOf() Date
Date
valueOf() JavaScript
date Date.getTime
JavaScript Math
Math
Math
Math
var pi_value=Math.PI;
var sqrt_value=Math.sqrt(15);
Math Date String Math()
Math.sin() Math
Math
FF: Firefox, IE: Internet Explorer
FF
IE
e 2.718
LN2
2 0.693
LN10
10 2.302
LOG2E
2 e 1.414
LOG10E
10 e 0.434
PI
3.14159
SQRT1_2
2 0.707
SQRT2
2 1.414
Math
FF: Firefox, IE: Internet Explorer
FF
IE
abs(x)
acos(x)
asin(x)
atan(x)
-PI/2 PI/2 x
atan2(y,x)
ceil(x)
cos(x)
exp(x)
floor(x)
log(x)
max(x,y)
x y
min(x,y)
x y
pow(x,y)
x y
random()
0 ~ 1
round(x)
sin(x)
sqrt(x)
tan(x)
toSource()
valueOf()
Math
JavaScript E
Math.E e 2.71828
Math.E
Euler
<script type="text/javascript">
document.write("Euler's number: " + Math.E);
</script>
JavaScript LN2
Math.LN2
2
<script type="text/javascript">
document.write("LN2: " + Math.LN2);
</script>
LN2: 0.6931471805599453
JavaScript LN10
Math.LN10
10
<script type="text/javascript">
document.write("LN10: " + Math.LN10);
</script>
LN10: 2.302585092994046
JavaScript LOG2E
Math.LOG2E
2 e
<script type="text/javascript">
document.write("LOG2E: " + Math.LOG2E);
</script>
LOG2E: 1.4426950408889634
JavaScript LOG10E
Math.LOG10E
10 e
<script type="text/javascript">
document.write("LOG10E: " + Math.LOG10E);
</script>
LOG10E: 0.4342944819032518
JavaScript PI
PI 3.141592653589793
Math.PI
PI
<script type="text/javascript">
document.write("PI: " + Math.PI);
</script>
PI: 3.141592653589793
JavaScript SQRT1_2
SQRT1_2 2 0.7071067811865476
Math.SQRT1_2
1/2
<script type="text/javascript">
document.write("SQRT1_2: " + Math.SQRT1_2);
</script>
SQRT1_2: 0.7071067811865476
JavaScript SQRT2
SQRT2 2 1.4142135623730951
Math.SQRT2
2
<script type="text/javascript">
document.write("SQRT2: " + Math.SQRT2);
</script>
SQRT2: 1.4142135623730951
JavaScript abs()
abs()
Math.abs(x)
<script type="text/javascript">
document.write(Math.abs(7.25) + "<br />")
document.write(Math.abs(-7.25) + "<br />")
document.write(Math.abs(7.25-10))
</script>
7.25
7.25
2.75
JavaScript acos()
acos()
Math.acos(x)
-1.0 ~ 1.0
x 0 PI
<script type="text/javascript">
document.write(Math.acos(0.64) + "<br />")
document.write(Math.acos(0) + "<br />")
document.write(Math.acos(-1) + "<br />")
document.write(Math.acos(1) + "<br />")
document.write(Math.acos(2))
</script>
0.8762980611683406
1.5707963267948965
3.141592653589793
0
NaN
JavaScript asin()
asin()
Math.asin(x)
-1.0 ~ 1.0
x -PI/2 PI/2
<script type="text/javascript">
document.write(Math.asin(0.64) + "<br />")
document.write(Math.asin(0) + "<br />")
document.write(Math.asin(-1) + "<br />")
document.write(Math.asin(1) + "<br />")
document.write(Math.asin(2))
</script>
0.6944982656265559
0
-1.5707963267948965
1.5707963267948965
NaN
JavaScript atan()
atan()
Math.atan(x)
x -PI/2 PI/2
atan()
<script type="text/javascript">
document.write(Math.atan(0.50) + "<br />")
document.write(Math.atan(-0.50) + "<br />")
document.write(Math.atan(5) + "<br />")
document.write(Math.atan(10) + "<br />")
document.write(Math.atan(-5) + "<br />")
document.write(Math.atan(-10))
</script>
0.4636476090008061
-0.4636476090008061
1.373400766945016
1.4711276743037347
-1.373400766945016
-1.4711276743037347
JavaScript atan2()
atan2() x (x,y)
Math.atan2(y,x)
-PI PI X (x,y)
Y X
atan2() (x,y)
<script type="text/javascript">
document.write(Math.atan2(0.50,0.50) + "<br />")
document.write(Math.atan2(-0.50,-0.50) + "<br />")
document.write(Math.atan2(5,5) + "<br />")
document.write(Math.atan2(10,20) + "<br />")
document.write(Math.atan2(-5,-5) + "<br />")
document.write(Math.atan2(-10,10))
</script>
0.7853981633974483
-2.356194490192345
0.7853981633974483
0.4636476090008061
-2.356194490192345
-0.7853981633974483
JavaScript ceil()
ceil()
Math.ceil(x)
ceil()
ceil()
<script type="text/javascript">
document.write(Math.ceil(0.60) + "<br />")
document.write(Math.ceil(0.40) + "<br />")
document.write(Math.ceil(5) + "<br />")
document.write(Math.ceil(5.1) + "<br />")
document.write(Math.ceil(-5.1) + "<br />")
document.write(Math.ceil(-5.9))
</script>
1
1
5
6
-5
-5
JavaScript cos()
cos()
Math.cos(x)
x -1.0 1.0
<script type="text/javascript">
document.write(Math.cos(3) + "<br />")
document.write(Math.cos(-3) + "<br />")
document.write(Math.cos(0) + "<br />")
document.write(Math.cos(Math.PI) + "<br />")
document.write(Math.cos(2*Math.PI))
</script>
-0.9899924966004454
-0.9899924966004454
1
-1
1
JavaScript exp()
exp() e x
Math.exp(x)
e x e 2.71828
exp()
<script type="text/javascript">
document.write(Math.exp(1) + "<br />")
document.write(Math.exp(-1) + "<br />")
document.write(Math.exp(5) + "<br />")
document.write(Math.exp(10) + "<br />")
</script>
2.718281828459045
0.36787944117144233
148.4131591025766
22026.465794806718
JavaScript floor()
floor()
Math.floor(x)
x x
floor()
0
0
5
5
-6
-6
JavaScript log()
log()
Math.log(x)
x 0
log()
<script type="text/javascript">
document.write(Math.log(2.7183) +
document.write(Math.log(2) + "<br
document.write(Math.log(1) + "<br
document.write(Math.log(0) + "<br
document.write(Math.log(-1))
</script>
"<br />")
/>")
/>")
/>")
1.0000066849139877
0.6931471805599453
0
-Infinity
NaN
JavaScript max()
max()
Math.max(x...)
0 ECMASCript v3
-Infinity NaN
NaN
max()
<script type="text/javascript">
document.write(Math.max(5,7) + "<br />")
document.write(Math.max(-3,5) + "<br />")
document.write(Math.max(-3,-5) + "<br />")
document.write(Math.max(7.25,7.30))
</script>
7
5
-3
7.3
JavaScript min()
min()
Math.min(x,y)
0 ECMASCript v3
Infinity NaN
NaN
min()
<script type="text/javascript">
document.write(Math.min(5,7) + "<br />")
document.write(Math.min(-3,5) + "<br />")
document.write(Math.min(-3,-5) + "<br />")
document.write(Math.min(7.25,7.30))
</script>
5
-3
-5
7.25
JavaScript pow()
pow() x y
Math.pow(x,y)
x y
NaN
Infinity
pow()
<script type="text/javascript">
1
0
1
1
8
-8
16
16
JavaScript random()
random() 0 ~ 1
Math.random()
0.0 ~ 1.0
0 1
<script type="text/javascript">
document.write(Math.random())
</script>
0.21242664568126202
JavaScript round()
round()
Math.round(x)
0.5
3.5 4 -3.5 -3
<script type="text/javascript">
document.write(Math.round(0.60) + "<br />")
document.write(Math.round(0.50) + "<br />")
document.write(Math.round(0.49) + "<br />")
document.write(Math.round(-4.40) + "<br />")
document.write(Math.round(-4.60))
</script>
1
1
0
-4
-5
JavaScript sin()
sin()
Math.sin(x)
0.017453293 2PI/360
x -1.0 1.0
<script type="text/javascript">
document.write(Math.sin(3) + "<br />")
document.write(Math.sin(-3) + "<br />")
document.write(Math.sin(0) + "<br />")
document.write(Math.sin(Math.PI) + "<br />")
document.write(Math.sin(Math.PI/2)
</script>
0.1411200080598672
-0.1411200080598672
0
1.2246063538223772e-16
1
JavaScript sqrt()
sqrt()
Math.sqrt(x)
x x 0 NaN
Math.pow()
var
var
var
var
var
a=Math.sqrt(0);
b=Math.sqrt(1);
c=Math.sqrt(9);
d=Math.sqrt(0.64);
e=Math.sqrt(-9);
0
1
3
0.8
NaN
JavaScript tan()
tan()
Math.tan(x)
0.017453293 2PI/360
<script type="text/javascript">
document.write(Math.tan(0.50) + "<br />")
document.write(Math.tan(-0.50) + "<br />")
document.write(Math.tan(5) + "<br />")
document.write(Math.tan(10) + "<br />")
document.write(Math.tan(-5) + "<br />")
document.write(Math.tan(-10))
</script>
0.5463024898437905
-0.5463024898437905
-3.380515006246586
0.6483608274590866
3.380515006246586
-0.6483608274590866
JavaScript toSource()
toSource()
object.toSource()
Internet Explorer
toSource()
<script type="text/javascript">
function employee(name,job,born)
{
this.name=name;
this.job=job;
this.born=born;
}
var bill=new employee("Bill Gates","Engineer",1985);
document.write(bill.toSource());
</script>
JavaScript valueOf()
valueOf() Math
Math
valueOf() JavaScript
mathObject.valueOf()
Number
Number
Number
var myNum=new Number(value);
var myNum=Number(value);
value Number
Number
FF: Firefox, IE: Internet Explorer
FF
IE
constructor
Number
1.0
4.0
MAX_VALUE
1.0
4.0
MIN_VALUE
1.0
4.0
NaN
1.0
4.0
NEGATIVE_INFINITY
1.0
4.0
POSITIVE_INFINITY
1.0
4.0
prototype
1.0
4.0
Number
FF: Firefox, IE: Internet Explorer
FF
IE
toString
1.0
4.0
toLocaleString
1.0
4.0
toFixed
1.0
5.5
toExponential
1.0
5.5
toPrecision
1.0
5.5
valueOf
Number
1.0
4.0
Number
JavaScript JavaScript Number
JavaScript
JavaScript 1.1 Number() Number
Number() new
Number()
NaN
5 5
NaN
Number() Number
MAX_VALUE
var big = Number.MAX_VALUE
var n = 123;
var binary_value = n.toString(2);
JavaScript
ECMAScript
class ECMAScript
JavaScript constructor
constructor Boolean
object.constructor
constructor
<script type="text/javascript">
var test=new Boolean();
if (test.constructor==Array)
{
document.write("This is an Array");
}
if (test.constructor==Boolean)
{
document.write("This is a Boolean");
}
if (test.constructor==Date)
{
document.write("This is a Date");
}
if (test.constructor==String)
{
document.write("This is a String");
}
</script>
This is a Boolean
JavaScript MAX_VALUE
Number.MAX_VALUE
JavaScript
<script type="text/javascript">
document.write(Number.MAX_VALUE);
</script>
1.7976931348623157e+308
JavaScript MIN_VALUE
MIN_VALUE JavaScript 0
5 x 10-324
Number.MIN_VALUE
JavaScript
<script type="text/javascript">
document.write(Number.MIN_VALUE);
</script>
5e-324
JavaScript NaN
NaN Number
isNaN() NaN
Number.NaN
Number.NaN
parseInt() parseFloat()
Number.NaN
JavaScript NaN Number.NaNNaN
Number.NaN
isNaN()
ECMAScript v1 NaN Number.NaN
isNaN() NaN
NaN
<script type="text/javascript">
var Month=30;
if (Month < 1 || Month > 12)
{
Month = Number.NaN;
}
document.write(Month);
</script>
Nan
JavaScript NEGATIVE_INFINITY
NEGATIVE_INFINITY Number.MIN_VALUE
Number.NEGATIVE_INFINITY
Number.NEGATIVE_INFINITY JavaScript
-Number.MAX_VALUE
JavaScript NEGATIVE_INFINITY -Infinity
0
ECMAScript v1 -Infinity Number.NEGATIVE_INFINITY
NEGATIVE_INFINITY
<script type="text/javascript">
var x=(-Number.MAX_VALUE)*2
if (x==Number.NEGATIVE_INFINITY)
{
document.write("Value of x: " + x);
}
</script>
Value of x: -Infinity
JavaScript POSITIVE_INFINITY
POSITIVE_INFINITY Number.MAX_VALUE
Number.POSITIVE_INFINITY
Number.POSITIVE_INFINITY JavaScript
Number.MAX_VALUE
JavaScript POSITIVE_INFINITY Infinity
0
ECMAScript v1 Infinity Number.POSITIVE_INFINITY
POSITIVE_INFINITY
<script type="text/javascript">
var x=(Number.MAX_VALUE)*2
if (x==Number.POSITIVE_INFINITY)
{
document.write("Value of x: " + x);
}
</script>
Value of x: Infinity
JavaScript toString()
toString() Number
NumberObject.toString(radix)
radix
2 ~ 36 10
10 ECMAScript
radix 2 NumberObject
Number TypeError
<script type="text/javascript">
var number = new Number(1337);
document.write (number.toString())
</script>
1337
JavaScript toLocaleString()
toLocaleString() Number
NumberObject.toLocaleString()
Number TypeError
JavaScript toFixed()
toFixed() Number
NumberObject.toFixed(num)
num
0 ~ 20 0 20
0
NumberObject num
0 num
le+21 NumberObject.toString()
num RangeError0 ~ 20
Number TypeError
JavaScript toExponential()
toExponential()
NumberObject.toExponential(num)
num
0 ~ 20 0 20
NumberObject
num 0
num RangeError0 ~ 20
Number TypeError
JavaScript toPrecision()
toPrecision()
NumberObject.toPrecision(num)
num
1 ~ 21 1
21 num
toString()
num RangeError1 ~ 21
Number TypeError
JavaScript valueOf()
valueOf()
valueOf() JavaScript
NumberObject.valueOf()
NumberObject
Number TypeError
JavaScript String
String
String
String
new String(s);
String(s);
s String
String() new String
s s
new String() s
String
FF: Firefox, IE: Internet Explorer
FF
IE
constructor
length
prototype
String
FF: Firefox, IE: Internet Explorer
FF
IE
anchor()
HTML
big()
blink()
bold()
charAt()
charCodeAt()
Unicode
concat()
fixed()
fontcolor()
fontsize()
fromCharCode()
indexOf()
italics()
lastIndexOf()
link()
localeCompare()
match()
replace()
search()
slice()
small()
split()
strike()
sub()
substr()
substring()
sup()
toLocaleLowerCase()
toLocaleUpperCase()
toLowerCase()
toUpperCase()
toSource()
toString()
valueOf()
String
JavaScript
String length
String
JavaScript immutableString
String.toUpperCase()
JavaScript
ECMAScript
class ECMAScript
JavaScript length
length
stringObject.length
length
<script type="text/javascript">
var txt="Hello World!"
document.write(txt.length)
</script>
12
JavaScript anchor()
anchor() HTML
stringObject.anchor(anchorname)
anchorname
<script type="text/javascript">
var txt="Hello world!"
document.write(txt.anchor("myanchor"))
</script>
HTML
<a name="myanchor">Hello world!</a>
JavaScript big()
big()
stringObject.big()
"Hello world!"
<script type="text/javascript">
var str="Hello world!"
document.write(str.big())
</script>
JavaScript blink()
blink()
stringObject.blink()
Internet Explorer
"Hello world!"
<script type="text/javascript">
var str="Hello world!"
document.write(str.blink())
</script>
JavaScript bold()
bold()
stringObject.bold()
"Hello world!"
<script type="text/javascript">
var str="Hello world!"
document.write(str.bold())
</script>
JavaScript charAt()
charAt()
JavaScript
1
stringObject.charAt(index)
index
0 index 0 string.length
"Hello world!" 1
<script type="text/javascript">
var str="Hello world!"
document.write(str.charAt(1))
</script>
JavaScript charCodeAt()
charCodeAt() charAt()
stringObject.charCodeAt(index)
index
0 index
charCodeAt() NaN
101
JavaScript concat()
concat()
stringObject.concat(stringX,stringX,...,stringX)
stringX
concat() stringObject
stringObject
stringObject.concat() Array.concat()
" + "
concat()
<script type="text/javascript">
var str1="Hello "
var str2="world!"
document.write(str1.concat(str2))
</script>
Hello world!
JavaScript fixed()
fixed()
stringObject.fixed()
"Hello world!"
<script type="text/javascript">
var str="Hello world!"
document.write(str.fixed())
</script>
JavaScript fontcolor()
fontcolor()
stringObject.fontcolor(color)
color
font-color(red)RGB (rgb(255,0,0))
(#FF0000)
"Hello world!"
<script type="text/javascript">
var str="Hello world!"
document.write(str.fontcolor("Red"))
</script>
JavaScript fontsize()
fontsize()
stringObject.fontsize(size)
size 1 7
"Hello world!"
<script type="text/javascript">
var str="Hello world!"
document.write(str.fontsize(7))
</script>
JavaScript fromCharCode()
fromCharCode() Unicode
String.fromCharCode(numX,numX,...,numX)
numX
Unicode Unicode
String Unicode
String
String.fromCharCode() myStringObject.fromCharCode()
Unicode "HELLO" "ABC"
<script type="text/javascript">
document.write(String.fromCharCode(72,69,76,76,79))
document.write("<br />")
document.write(String.fromCharCode(65,66,67))
</script>
HELLO
ABC
JavaScript indexOf()
indexOf()
stringObject.indexOf(searchvalue,fromindex)
searchvalue
fromindex
0
stringObject.length - 1
stringObject searchvalue
fromindex fromindex
searchvalue searchvalue stringObject 0
indexOf()
-1
"Hello world!"
<script type="text/javascript">
var str="Hello world!"
document.write(str.indexOf("Hello") + "<br />")
document.write(str.indexOf("World") + "<br />")
document.write(str.indexOf("world"))
</script>
0
-1
6
JavaScript italics()
italics()
stringObject.italics()
"Hello world!"
<script type="text/javascript">
var str="Hello world!"
document.write(str.italics())
</script>
JavaScript lastIndexOf()
lastIndexOf()
stringObject.lastIndexOf(searchvalue,fromindex)
searchvalue
fromindex
0
stringObject.length - 1
stringObject searchvalue
fromindex fromindex
searchvalue searchvalue stringObject stringObject
0
lastIndexOf()
-1
"Hello world!"
<script type="text/javascript">
var str="Hello world!"
document.write(str.lastIndexOf("Hello") + "<br />")
document.write(str.lastIndexOf("World") + "<br />")
document.write(str.lastIndexOf("world"))
</script>
0
-1
6
JavaScript link()
link()
stringObject.link(url)
url
URL
JavaScript localeCompare()
stringObject.localeCompare(target)
target
stringObject
ch c d
localeCompare() ECMAscript
var str;
str.sort (function(a,b){return a.localeCompare(b)})
JavaScript match()
match()
indexOf() lastIndexOf()
stringObject.match(searchvalue)
stringObject.match(regexp)
searchvalue
regexp
RegExp RegExp
RegExp RegExp
regexp g
match() stringObject regexp
regexp g
regexp g match() stringObject
match() null
0
index stringObject
input stringObject
regexp g match() stringObject
null
1
"Hello world!"
<script type="text/javascript">
var str="Hello world!"
document.write(str.match("world") + "<br />")
document.write(str.match("World") + "<br />")
document.write(str.match("worlld") + "<br />")
document.write(str.match("world!"))
</script>
world
null
null
world!
2
<script type="text/javascript">
var str="1 plus 2 equal 3"
document.write(str.match(/\d+/g))
</script>
1,2,3
JavaScript replace()
replace()
stringObject.replace(regexp/substr,replacement)
regexp/substr
RegExp
RegExp
replacement
replacement regexp
$1$2...$99
regexp 1 99
$&
regexp
$`
$'
$$
0 stringObject
stringObject
1
"W3School" "Microsoft"
<script type="text/javascript">
var str="Visit Microsoft!"
document.write(str.replace(/Microsoft/, "W3School"))
</script>
Visit W3School!
2
"Microsoft" "W3School"
<script type="text/javascript">
var str="Welcome to Microsoft! "
str=str + "We are proud to announce that Microsoft has "
str=str + "one of the largest Web Developers sites in the world."
document.write(str.replace(/Microsoft/g, "W3School"))
</script>
);
JavaScript search()
search()
stringObject.search(regexp)
regexp
stringObject RegExp
stringObject regexp
-1
1
"W3School"
<script type="text/javascript">
var str="Visit W3School!"
document.write(str.search(/W3School/))
</script>
6
w3school search()
<script type="text/javascript">
var str="Visit W3School!"
document.write(str.search(/w3school/))
</script>
-1
2
<script type="text/javascript">
var str="Visit W3School!"
document.write(str.search(/w3school/i))
</script>
JavaScript slice()
slice()
stringObject.slice(start,end)
start
-1 -2
end
start
String.slice() Array.slice()
1
6
<script type="text/javascript">
var str="Hello happy world!"
document.write(str.slice(6))
</script>
happy world!
2
6 11
<script type="text/javascript">
var str="Hello happy world!"
document.write(str.slice(6,11))
</script>
happy
JavaScript small()
small()
stringObject.small()
"Hello world!"
<script type="text/javascript">
var str="Hello world!"
document.write(str.small())
</script>
JavaScript split()
split()
stringObject.split(separator,howmany)
separator
stringObject
howmany
separator stringObject
separator
separator
String.split() Array.join
<script type="text/javascript">
var str="How are you doing today?"
document.write(str.split(" ") + "<br />")
document.write(str.split("") + "<br />")
document.write(str.split(" ",3))
</script>
How,are,you,doing,today?
H,o,w, ,a,r,e, ,y,o,u, ,d,o,i,n,g, ,t,o,d,a,y,?
How,are,you
2
"2:3:4:5".split(":")
//["2", "3", "4", "5"]
"|a|b|c".split("|") //["", "a", "b", "c"]
3
"hello".split("")
howmany
"hello".split("", 3)
JavaScript strike()
strike()
stringObject.strike()
"Hello world!"
<script type="text/javascript">
var str="Hello world!"
document.write(str.strike())
</script>
JavaScript sub()
sub()
stringObject.sub()
"Hello world!"
<script type="text/javascript">
var str="Hello world!"
document.write(str.sub())
</script>
JavaScript substr()
substr() start
stringObject.substr(start,length)
start
-1 -2
length
stringObject
ECMAscript
IE 4 start BUG start 0
BUG
1
substr()
<script type="text/javascript">
var str="Hello world!"
document.write(str.substr(3))
</script>
lo world!
2
substr()
<script type="text/javascript">
var str="Hello world!"
document.write(str.substr(3,7))
</script>
lo worl
JavaScript substring()
substring()
stringObject.substring(start,stop)
start
stringObject
stop
stringObject
1
substring()
<script type="text/javascript">
var str="Hello world!"
document.write(str.substring(3))
</script>
lo world!
2
substring()
<script type="text/javascript">
var str="Hello world!"
document.write(str.substring(3,7))
</script>
lo w
JavaScript sup()
sup()
stringObject.sup()
"Hello world!"
<script type="text/javascript">
var str="Hello world!"
document.write(str.sup())
</script>
JavaScript toLocaleLowerCase()
toLocaleLowerCase()
stringObject.toLocaleLowerCase()
stringObject
toLowerCase() toLocaleLowerCase()
toLowerCase()
"Hello world!"
<script type="text/javascript">
JavaScript toLocaleUpperCase()
toLocaleUpperCase()
stringObject.toLocaleUpperCase()
stringObject
toUpperCase() toLocaleUpperCase()
toUpperCase()
"Hello world!"
<script type="text/javascript">
var str="Hello World!"
document.write(str.toLocaleUpperCase())
</script>
JavaScript toLowerCase()
toLowerCase()
stringObject.toLowerCase()
stringObject
"Hello world!"
<script type="text/javascript">
var str="Hello World!"
document.write(str.toLowerCase())
</script>
JavaScript toUpperCase()
toUpperCase()
stringObject.toUpperCase()
stringObject
"Hello world!"
<script type="text/javascript">
var str="Hello World!"
document.write(str.toUpperCase())
</script>
JavaScript toString()
toString()
stringObject.toString()
stringObject
String TypeError
stringObject.valueOf()
JavaScript
ECMAScript
ECMAScript
JavaScript valueOf()
valueOf() String
String
valueOf() JavaScript
stringObject.valueOf()
String TypeError
JavaScript RegExp
RegExp
RegExp
/pattern/attributes
RegExp
new RegExp(pattern, attributes);
pattern
attributes "g""i" "m"
ECMAScript m pattern
RegExp pattern
RegExp() RegExp
RegExp
new RegExp() new
pattern pattern RegExp
[abc]
[^abc]
[0-9]
0 9
[a-z]
a z
[A-Z]
A Z
[A-z]
A z
[adgk]
[^adgk]
(red|blue|green)
Metacharacter
\w
\W
\d
\D
\s
\S
\b
\B
\0
NUL
\n
\f
\r
\t
\v
\xxx
xxx
\xdd
dd
\uxxxx
xxxx Unicode
n+
n*
n?
n{X}
X n
n{X,Y}
X Y n
n{X,}
X n
n$
^n
?=n
?!n
RegExp
FF: Firefox, IE: Internet Explorer
FF
IE
global
RegExp g
ignoreCase
RegExp i
lastIndex
multiline
RegExp m
source
RegExp
FF: Firefox, IE: Internet Explorer
FF
IE
compile
exec
test
true false
String
FF: Firefox, IE: Internet Explorer
FF
IE
search
match
replace
split
JavaScript RegExp i
new RegExp("regexp","i")
/regexp/i
"w3school"
var str="Visit W3School";
var patt1=/w3school/i;
Visit W3School
JavaScript RegExp g
new RegExp("regexp","g")
/regexp/g
"is"
var str="Is this all there is?";
var patt1=/is/g;
[abc]
new RegExp("[abc]")
/[abc]/
[abc]
[a-h]
var str="Is this all there is?";
var patt1=/[a-h]/g;
[^abc]
new RegExp("[^xyz]")
/[^xyz]/
[^abc]
[a-h]
var str="Is this all there is?";
var patt1=/[^a-h]/g;
Is this all there is?
JavaScript RegExp .
new RegExp("regexp.")
/regexp./
"h.t"
var str="That's hot!";
var patt1=/h.t/g;
That's hot!
JavaScript RegExp \w
\w
new RegExp("\w")
/\w/
\w
Give 100%!
JavaScript RegExp \W
\W
a-zA-Z0-9
new RegExp("\W")
/\W/
\W
Give 100%!
JavaScript RegExp \d
\d
new RegExp("\d")
/\d/
\d
Give 100%!
JavaScript RegExp \D
\D
new RegExp("\D")
/\D/
\D
Give 100%!
JavaScript RegExp \s
\s
(space character)
(tab character)
(carriage return character)
(new line character)
(vertical tab character)
(form feed character)
new RegExp("\s")
/\s/
\s
Is this all there is?
JavaScript RegExp \S
\S
(space character)
(tab character)
(carriage return character)
(new line character)
(vertical tab character)
(form feed character)
new RegExp("\S")
/\S/
\S
JavaScript RegExp \b
\b
[\b]
null
\b
new RegExp("\bregexp")
/\bregexp/
\b
"W3"
var str="Visit W3School";
var patt1=/\bW3/g;
Visit W3School
JavaScript RegExp \B
\B
null
\B
/\B../ "noonday" 'oo' /y\B./ "possibly yesterday." 'ye'
new RegExp("\Bregexp")
/\Bregexp/
\B
"School"
var str="Visit W3School";
var patt1=/\BSchool/g;
Visit W3School
JavaScript RegExp \n
\n
\n -1
new RegExp("\n")
/\n/
\n
\xxx xxx
null
new RegExp("\xxx")
/\xxx/
\xxx
127 (W)
var str="Visit W3School. Hello World!";
var patt1=/\127/g;
\xdd dd
null
new RegExp("\xdd")
/\xdd/
\xdd
57 (W)
var str="Visit W3School. Hello World!";
var patt1=/\x57/g;
new RegExp("\uxxxx")
/\uxxxx/
\uxxxx
0057 (W)
var str="Visit W3School. Hello World!";
var patt1=/\u0057/g;
JavaScript RegExp +
n+ n
new RegExp("n+")
/n+/
1
"o"
var str="Hellooo World! Hello W3School!";
var patt1=/o+/g;
Hellooo World! Hello W3School!
2
JavaScript RegExp *
n+ n
new RegExp("n*")
/n*/
1
"l" "o"
1, 100 or 1000?
JavaScript RegExp ?
n? n
new RegExp("n?")
/n?/
"1" "0"
var str="1, 100 or 1000?";
var patt1=/10?/g;
1, 100 or 1000?
n{X,} X n
X
new RegExp("n{X}")
/n{X}/
{X}
100, 1000 or 10000?
n{X,Y} X Y n
X Y
new RegExp("n{X,Y}")
/n{X,Y}/
{X,Y}
n{X,} X n
X
new RegExp("n{X,}")
/n{X,}/
{X,}
JavaScript RegExp $
n$ n
new RegExp("n$")
/n$/
"is"
var str="Is this his";
var patt1=/is$/g;
Is this his
JavaScript RegExp ^
n^ n
new RegExp("^n")
/^n/
"is"
var str="Is this his";
var patt1=/^Is/g;
Is this his
JavaScript RegExp ?=
?=n n
new RegExp("regexp(?=n)")
/regexp(?=n)/
?=
"all" "is"
JavaScript RegExp ?!
?!n n
new RegExp("regexp(?!n)")
/regexp(?!n)/
?!
"all" "is"
var str="Is this all there is";
var patt1=/is(?! all)/gi;
JavaScript global
global "g"
g true false
RegExpObject.global
g
<script type="text/javascript">
var str = "Visit W3School.com.cn";
var patt1 = new RegExp("W3");
if(patt1.global)
{
alert("Global property is set");
}
else
{
alert("Global property is NOT set.");
}
</script>
JavaScript ignoreCase
ignoreCase "i"
"i" true false
RegExpObject.ignoreCase
i
<script type="text/javascript">
var str = "Visit W3School";
var patt1 = new RegExp("W3");
if(patt1.ignoreCase)
{
alert("ignoreCase property is set");
}
else
{
alert("ignoreCase property is NOT set.");
}
</script>
JavaScript lastIndex
lastIndex
RegExpObject.lastIndex
exec() test() lastIndex 0
g RegExp lastIndex
lastIndex
<script type="text/javascript">
var str = "The rain in Spain stays mainly in the plain";
var patt1 = new RegExp("ain", "g");
patt1.test(str)
document.write("Match found. index now at: " + patt1.lastIndex);
</script>
JavaScript multiline
multiline m
^ $
RegExpObject.multiline
m
<script type="text/javascript">
var str = "Visit W3School.com.cn";
var patt1 = new RegExp("W3","m");
if(patt1.multiline)
{
alert("Multiline property is set");
}
else
{
alert("Multiline property is NOT set.");
}
</script>
JavaScript source
source
gim
RegExpObject.source
<script type="text/javascript">
var str = "Visit W3School.com.cn";
var patt1 = new RegExp("W3S","g");
document.write("The regular expression is: " + patt1.source);
</script>
JavaScript compile()
compile()
compile()
RegExpObject.compile(regexp,modifier)
regexp
modifier
Every person in the world! Every woperson on earth!
Every person in the world! Every person on earth!
JavaScript exec()
exec()
RegExpObject.exec(string)
string
null
exec() test()
String
exec() null 0
1 RegExpObject 1
2 RegExpObject 2
length exec()
index input
string RegExp exec()
String.match()
RegExpObject exec()
RegExpObject lastIndex string exec()
RegExpObject lastIndex
exec()
exec() null lastIndex
lastIndex 0
RegExpObject exec()
exec() String.match()
exec()
W3School
<script type="text/javascript">
var str = "Visit W3School";
var patt = new RegExp("W3School","g");
var result;
while ((result = patt.exec(str)) != null)
document.write(result);
document.write("<br />");
document.write(patt.lastIndex);
}
</script>
W3School
14
JavaScript test()
test() .
RegExpObject.test(string)
string
RegExp r test() s
(r.exec(s) != null)
"W3School"
<script type="text/javascript">
var str = "Visit W3School";
var patt1 = new RegExp("W3School");
var result = patt1.test(str);
document.write("Result: " + result);
</script>
Result: true
JavaScript
JavaScript
FF: Firefox, IE: Internet Explorer
FF
IE
decodeURI()
URI
5.5
decodeURIComponent()
URI
5.5
encodeURI()
URI
5.5
encodeURIComponent()
URI
5.5
escape()
eval()
JavaScript
getClass()
JavaObject JavaClass
isFinite()
isNaN()
Number()
parseFloat()
parseInt()
String()
unescape()
escape()
FF
IE
Infinity
java
java.* JavaPackage
NaN
Packages
JavaPackage
undefined
5.5
JavaScript
JavaScript this
JavaScript parseInt()
parseInt JavaScript
JavaScript
ECMAScript JavaScript JavaScript
JavaScript for/in
JavaScript decodeURI()
decodeURI(URIstring)
URIstring
URI
URIstring
decodeURI() URI
<script type="text/javascript">
var test1="http://www.w3school.com.cn/My first/"
document.write(encodeURI(test1)+ "<br />")
document.write(decodeURI(test1))
</script>
http://www.w3school.com.cn/My%20first/
http://www.w3school.com.cn/My first/
JavaScript decodeURIComponent()
decodeURIComponent(URIstring)
URIstring
URI
URIstring
decodeURIComponent() URI
<script type="text/javascript">
var test1="http://www.w3school.com.cn/My first/"
document.write(encodeURIComponent(test1)+ "<br />")
document.write(decodeURIComponent(test1))
</script>
http%3A%2F%2Fwww.w3school.com.cn%2FMy%20first%2F
http://www.w3school.com.cn/My first/
JavaScript encodeURI()
encodeURI() URI
encodeURI(URIstring)
URIstring
URI
URIstring
ASCII ASCII - _ . !
~*'()
URI URI ASCII
encodeURI() ;/?:@&=+$,#
URI ? # encodeURIComponent()
encodeURI() URI
<script type="text/javascript">
document.write(encodeURI("http://www.w3school.com.cn")+ "<br />")
document.write(encodeURI("http://www.w3school.com.cn/My first/"))
document.write(encodeURI(",/?:@&=+$#"))
</script>
http://www.w3school.com.cn
http://www.w3school.com.cn/My%20first/
,/?:@&=+$#
JavaScript encodeURIComponent()
encodeURIComponent() URI
encodeURIComponent(URIstring)
URIstring
URI
URIstring
ASCII ASCII - _ . !
~*'()
;/?:@&=+$,# URI
encodeURIComponent() encodeURI()
URI
encodeURIComponent() URI
encodeURIComponent() URI
<script type="text/javascript">
document.write(encodeURIComponent("http://www.w3school.com.cn"))
document.write("<br />")
document.write(encodeURIComponent("http://www.w3school.com.cn/p
1/"))
document.write("<br />")
document.write(encodeURIComponent(",/?:@&=+$#"))
</script>
http%3A%2F%2Fwww.w3school.com.cn
http%3A%2F%2Fwww.w3school.com.cn%2Fp%201%2F
%2C%2F%3F%3A%40%26%3D%2B%24%23
JavaScript escape()
escape()
escape(string)
string
string
ASCII ASCII *
@ - _ + . /
unescape() escape()
ECMAScript v3 decodeURI() decodeURIComponent()
escape()
<script type="text/javascript">
document.write(escape("Visit W3School!") + "<br />")
document.write(escape("?!=()#%&"))
</script>
Visit%20W3School%21
%3F%21%3D%28%29%23%25%26
JavaScript eval()
eval() JavaScript
eval(string)
string
JavaScript
string
string
eval() String
eval eval()
ECMAScript EvalError
SyntaxError
eval() EvalError
eval() Javascript eval()
eval()
1
eval()
<script type="text/javascript">
eval("x=10;y=20;document.write(x*y)")
document.write(eval("2+2"))
var x=10
document.write(eval(x+17))
</script>
200
4
27
2
eval()
eval("2+3") // 5
var myeval = eval; // EvalError
myeval("2+3");
// EvalError
eval()
try
{
alert("Result:" + eval(prompt("Enter an expression:","")));
}
catch(exception) {
alert(exception);
}
JavaScript getClass()
getClass(javaobj)
javaobj
JavaObject
javaobj JavaClass
JavaObject JavaClass
JavaClass JavaClass Java Java Java
Java JavaObject
JavaScript isFinite()
isFinite()
isFinite(number)
number
isFinite()
<script type="text/javascript">
document.write(isFinite(123)+ "<br />")
document.write(isFinite(-1.23)+ "<br />")
document.write(isFinite(5-2)+ "<br />")
document.write(isFinite(0)+ "<br />")
document.write(isFinite("Hello")+ "<br />")
document.write(isFinite("2005/12/12")+ "<br />")
</script>
true
true
true
true
false
false
JavaScript isNaN()
isNaN()
isNaN(x)
x NaN true x
, false
isNaN() NaN 0
NaN false
NaN == === isNaN()
<script>
document.write(isNaN(123));
document.write(isNaN(-1.23));
document.write(isNaN(5-2));
document.write(isNaN(0));
document.write(isNaN("Hello"));
document.write(isNaN("2005/12/12"));
</script>
false
false
false
false
true
true
JavaScript Number()
Number()
Number(object)
object
JavaScript
<script type="text/javascript">
var
var
var
var
var
test1=
test2=
test3=
test4=
test5=
new
new
new
new
new
Boolean(true);
Boolean(false);
Date();
String("999");
String("999 888");
document.write(Number(test1)+
document.write(Number(test2)+
document.write(Number(test3)+
document.write(Number(test4)+
document.write(Number(test5)+
"<br
"<br
"<br
"<br
"<br
/>");
/>");
/>");
/>");
/>");
</script>
1
0
1256657776588
999
NaN
JavaScript parseFloat()
parseFloat()
parseFloat(string)
string
parseFloat
parseFloat +
- (0-9)e E
parseFloat NaN
isNaN parseFloat NaN NaN
NaN
parseFloat() NaN
parseInt()
1
parseFloat()
<script type="text/javascript">
document.write(parseFloat("10"))
document.write(parseFloat("10.00"))
document.write(parseFloat("10.33"))
document.write(parseFloat("34 45 66"))
document.write(parseFloat(" 60 "))
document.write(parseFloat("40 years"))
document.write(parseFloat("He was 40"))
</script>
10
10
10.33
34
60
40
NaN
2
3.14
<script type="text/javascript">
document.write(parseFloat("3.14"))
document.write(parseFloat("314e-2"))
document.write(parseFloat("0.0314E+2"))
document.write(parseFloat("3.14more non-digit characters"))
</script>
3.14
3
NaN
<script type="text/javascript">
document.write(parseFloat("FF2"))
</script>
NaN
JavaScript parseInt()
parseInt()
parseInt(string, radix)
string
radix
2 ~ 36
0 10 0x
0X 16
2 36 parseInt() NaN
parseFloat() NaN
parseInt()
parseInt("10");
parseInt("19",10);
parseInt("11",2);
parseInt("17",8);
parseInt("1f",16);
parseInt("010");
// 10
// 19 (10+9)
// 3 (2+1)
// 15 (8+7)
// 31 (16+15)
// 10 8
JavaScript String()
String()
String(object)
object
JavaScript
<script type="text/javascript">
var
var
var
var
var
var
var
document.write(String(test1)+
document.write(String(test2)+
document.write(String(test3)+
document.write(String(test4)+
document.write(String(test5)+
document.write(String(test6)+
document.write(String(test7)+
"<br
"<br
"<br
"<br
"<br
"<br
"<br
/>");
/>");
/>");
/>");
/>");
/>");
/>");
</script>
true
false
true
false
Wed Oct 28 00:17:40 UTC+0800 2009
999 888
12345
JavaScript unescape()
unescape() escape()
unescape(string)
string
string
%xx %uxxxx x
Unicode \u00xx \uxxxx
ECMAScript v3 unescape()
decodeURI() decodeURIComponent()
escape() unescape()
<script type="text/javascript">
var test1="Visit W3School!"
test1=escape(test1)
document.write (test1 + "<br />")
test1=unescape(test1)
document.write(test1 + "<br />")
</script>
Visit%20W3School%21
Visit W3School!
JavaScript Infinity
Infinity
Infinity
infinity
<script type="text/javascript">
var t1=1.7976931348623157E+10308
document.write(t1)
document.write("<br />")
var t2=-1.7976931348623157E+10308
document.write(t2)
</script>
Infinity
-Infinity
JavaScript java
java.* JavaPackage
java
JavaScript NaN
NaN
NaN
isNaN() NaN
infinity
<script type="text/javascript">
var test1="300"
300
NaN
false
true
JavaScript Packages
JavaPackage
Packages
JavaScript undefined
undefined
=== == undefined
null
null undefined
<script type="text/javascript">
var t1=""
var t2
if (t1===undefined) {document.write("t1 is undefined")}
if (t2===undefined) {document.write("t2 is undefined")}
</script>
t2 is undefined
Window
Window
Window
frame iframe
HTML window
window
window
IE: Internet Explorer, F: Firefox, O: Opera.
Window
IE
frames[]
Window Window
<iframe> frames.length frames[]
frames[]
frames[]
Window
IE
closed
defaultStatus
No
document
Document
Document
history
History History
innerheight
No
No
No
innerwidth
No
No
No
length
location
Location
name
Location
Navigator
Navigator Navigator
opener
outerheight
No
No
No
outerwidth
No
No
No
pageXOffset
No
No
No
pageYOffset
No
No
No
parent
Screen
Screen Screen
self
Window 4
status
No
top
window
window self
x
y IE Safari Opera
screenLeft screenTop Firefox Safari
screenX screenY
screenLeft
screenTop
screenX
screenY
Window
IE
alert()
blur()
clearInterval()
setInterval() timeout
clearTimeout()
setTimeout() timeout
close()
confirm()
createPopup()
pop-up
No
No
focus()
moveBy()
moveTo()
open()
print()
prompt()
resizeBy()
resizeTo()
1.5
scrollBy()
scrollTo()
setInterval()
setTimeout()
Window
Window JavaScript Window
document
window.document
alert()
Window.alert()
Window JavaScript
frame[i]
//
self.frame[i] //
w.frame[i]
// w
parent
//
self.parent //
w.parent
// w
top
//
self.top
//
f.top
// f
Window.open() open()
opener
Window alert()
confirm() prompt
closed
Windows
closed true
window.closed
<html>
<head>
<script type="text/javascript">
function ifClosed()
{
defaultStatus
window.defaultStatus=sometext
<html>
<body>
<script type="text/javascript">
window.defaultStatus="This is the default text in the status bar!!";
</script>
<p>Look at the text in the statusbar.</p>
</body>
</html>
IE document.documentElement document.body IE
clientWidth clientHeight
name
open() <frame> name
window.name=name
<html>
<head>
<script type="text/javascript">
function checkWin()
{
document.write(myWindow.name)
}
</script>
</head>
<body>
<script type="text/javascript">
myWindow=window.open('','MyName','width=200,height=100')
myWindow.document.write("This is 'myWindow'")
</script>
<input type="button" value="What's the name of 'myWindow'?"
onclick="checkWin()">
</body>
</html>
opener Window
opener
window.opener
opener
<html>
<body>
<script type="text/javascript">
myWindow=window.open('','MyName','width=200,height=100')
myWindow.document.write("This is 'myWindow'")
myWindow.focus()
myWindow.opener.document.write("This is the parent window")
</script>
</body>
</html>
outerheight
window.outerheight=pixels
IE
100x100
<html>
<body>
<script type="text/javascript">
myWindow=window.open('','')
myWindow.outerheight="100"
myWindow.outerwidth="100"
myWindow.document.write("This is 'myWindow'")
myWindow.focus()
</script>
</body>
</html>
outerwidth
window.outerwidth=pixels
IE
100x100
<html>
<body>
<script type="text/javascript">
myWindow=window.open('','')
myWindow.outerheight="100"
myWindow.outerwidth="100"
myWindow.document.write("This is 'myWindow'")
myWindow.focus()
</script>
</body>
</html>
self Window
window.self
<html>
<head>
<script type="text/javascript">
function breakout()
{
if (window.top!=window.self)
{
window.top.location="tryjs_breakout.htm"
}
}
</script>
</head>
<body>
<input type="button" onclick="breakout()"
value="Break out of frame!">
</body>
</html>
status
window.status=sometext
status
status
defaultStatus
<html>
<body>
<script type="text/javascript">
window.status="Some text in the status bar!!"
</script>
</body>
</html>
top
top
top
window.top
<html>
<head>
<script type="text/javascript">
function breakout()
{
if (window.top!=window.self)
{
window.top.location="tryjs_breakout.htm"
}
}
</script>
</head>
<body>
<form>
Click the button to break out of the frame:
alert() OK
alert(message)
message
window HTML
<html>
<head>
<script type="text/javascript">
function display_alert()
{
alert("I am an alert box!!")
}
</script>
</head>
<body>
<input type="button" onclick="display_alert()"
value="Display alert box" />
</body>
</html>
blur()
window.blur()
blur() Window
<html>
<body>
<script type="text/javascript">
myWindow=window.open('','','width=200,height=100')
myWindow.document.write("This is 'myWindow'")
myWindow.blur()
</script>
</body>
</html>
clearInterval(id_of_setinterval)
id_of_setinterval
setInterval() ID
50 clock() clock
<html>
<body>
<input type="text" id="clock" size="35" />
<script language=javascript>
var int=self.setInterval("clock()",50)
function clock()
{
var t=new Date()
document.getElementById("clock").value=t
}
</script>
</form>
<button onclick="int=window.clearInterval(int)">
Stop interval</button>
</body>
</html>
clearTimeout(id_of_settimeout)
id_of_settimeout
setTimeout() ID
timedCount()
<html>
<head>
<script type="text/javascript">
var c=0
var t
function timedCount()
{
document.getElementById('txt').value=c
c=c+1
t=setTimeout("timedCount()",1000)
}
function stopCount()
{
clearTimeout(t)
}
</script>
</head>
<body>
<form>
<input type="button" value="Start count!" onClick="timedCount()">
<input type="text" id="txt">
close()
window.close()
<html>
<head>
<script type="text/javascript">
function closeWin()
{
myWindow.close()
}
</script>
</head>
<body>
<script type="text/javascript">
myWindow=window.open('','','width=200,height=100')
myWindow.document.write("This is 'myWindow'")
</script>
<input type="button" value="Close 'myWindow'"
onclick="closeWin()" />
</body>
</html>
confirm() OK
confirm(message)
message
window HTML
confirm() JavaScript
<html>
<head>
<script type="text/javascript">
function disp_confirm()
{
var r=confirm("Press a button")
if (r==true)
{
document.write("You pressed OK!")
}
else
{
document.write("You pressed Cancel!")
}
}
</script>
</head>
<body>
<input type="button" onclick="disp_confirm()"
value="Display a confirm box" />
</body>
</html>
createPopup() pop-up
window.createPopup()
<html>
<head>
<script type="text/javascript">
function show_popup()
{
var p=window.createPopup()
var pbody=p.document.body
pbody.style.backgroundColor="lime"
pbody.style.border="solid black 1px"
pbody.innerHTML="This is a pop-up! Click outside to close."
p.show(150,150,200,50,document.body)
}
</script>
</head>
<body>
<button onclick="show_popup()">Create pop-up!</button>
</body>
</html>
focus()
window.focus()
<html>
<body>
<script type="text/javascript">
myWindow=window.open('','','width=200,height=100')
myWindow.document.write("This is 'myWindow'")
myWindow.focus()
</script>
</body>
</html>
moveBy()
window.moveBy(x,y)
50
<html>
<head>
<script type="text/javascript">
function moveWin()
{
myWindow.moveBy(50,50)
}
</script>
</head>
<body>
<script type="text/javascript">
myWindow=window.open('','','width=200,height=100')
myWindow.document.write("This is 'myWindow'")
</script>
<input type="button" value="Move 'myWindow'"
onclick="moveWin()" />
</body>
</html>
moveTo()
window.moveTo(x,y)
<html>
<head>
<script type="text/javascript">
function moveWin()
{
myWindow.moveTo(50,50)
}
</script>
</head>
<body>
<script type="text/javascript">
myWindow=window.open('','','width=200,height=100')
myWindow.document.write("This is 'myWindow'")
</script>
<input type="button" value="Move 'myWindow'"
onclick="moveWin()" />
</body>
</html>
open()
window.open(URL,name,features,replace)
URL
URL
name
<a>
<form> target
open()
features
features
replace
URL
true - URL
false - URL
Window.open() Document.open()
Window.open() open()
1
www.w3school.com.cn
<html>
<head>
<script type="text/javascript">
function open_win()
{
window.open("http://www.w3school.com.cn")
}
</script>
</head>
<body>
<input type=button value="Open Window" onclick="open_win()" />
</body>
</html>
2
about:blank
<html>
<body>
<script type="text/javascript">
myWindow=window.open('','','width=200,height=100')
myWindow.document.write("This is 'myWindow'")
myWindow.focus()
</script>
</body>
</html>
Window Features
channelmode=yes|no|1|0
no
directories=yes|no|1|0
yes
fullscreen=yes|no|1|0
no
height=pixels
left=pixels
location=yes|no|1|0
yes
menubar=yes|no|1|0
yes
resizable=yes|no|1|0
yes
scrollbars=yes|no|1|0
yes
status=yes|no|1|0
yes
titlebar=yes|no|1|0
yes
toolbar=yes|no|1|0
yes
top=pixels
width=pixels
print()
print()
window.print()
1
<html>
<head>
<script type="text/javascript">
function printpage()
{
window.print()
}
</script>
</head>
<body>
<input type="button" value="Print this page"
onclick="printpage()" />
</body>
</html>
prompt()
prompt(text,defaultText)
text
HTML
defaultText
null
prompt() JavaScript
1
<html>
<head>
<script type="text/javascript">
function disp_prompt()
{
var name=prompt("Please enter your name","")
if (name!=null && name!="")
{
document.write("Hello " + name + "!")
}
}
</script>
</head>
<body>
<input type="button" onclick="disp_prompt()"
value="Display a prompt box" />
</body>
</html>
resizeBy()
resizeBy(width,height)
width
height
1
<html>
<head>
<script type="text/javascript">
function resizeWindow()
{
window.resizeBy(-100,-100)
}
</script>
</head>
<body>
<input type="button" onclick="resizeWindow()"
value="Resize window">
</body>
</html>
resizeTo()
resizeTo(width,height)
width
height
<html>
<head>
<script type="text/javascript">
function resizeWindow()
{
window.resizeTo(500,300)
}
</script>
</head>
<body>
<input type="button" onclick="resizeWindow()"
value="Resize window">
</body>
</html>
scrollBy()
scrollBy(xnum,ynum)
xnum
ynum
100
<html>
<head>
<script type="text/javascript">
function scrollWindow()
{
window.scrollBy(100,100)
}
</script>
</head>
<body>
<input type="button" onclick="scrollWindow()" value="Scroll" />
<p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p>
</body>
</html>
scrollTo()
scrollTo(xpos,ypos)
xpos
ypos
100,500
<html>
<head>
<script type="text/javascript">
function scrollWindow()
{
window.scrollTo(100,500)
}
</script>
</head>
<body>
<input type="button" onclick="scrollWindow()" value="Scroll" />
<p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p>
</body>
</html>
setInterval()
setInterval() clearInterval()
setInterval() ID clearInterval()
setInterval(code,millisec[,"lang"])
code
millisec
code
Window.clearInterval() code
<html>
<body>
<input type="text" id="clock" size="35" />
<script language=javascript>
var int=self.setInterval("clock()",50)
function clock()
{
var t=new Date()
document.getElementById("clock").value=t
}
</script>
</form>
<button onclick="int=window.clearInterval(int)">
Stop interval</button>
</body>
</html>
setTimeout()
setTimeout(code,millisec)
code
JavaScript
millisec
setTimeout() code setInterval() code
setTimeout()
<html>
<head>
<script type="text/javascript">
function timedMsg()
{
var t=setTimeout("alert('5 seconds!')",5000)
}
</script>
</head>
<body>
<form>
<input type="button" value="Display timed alertbox!"
onClick="timedMsg()">
</form>
<p>Click on the button above. An alert box will be
displayed after 5 seconds.</p>
</body>
</html>
Navigator
Navigator
Navigator
navigator
IE: Internet Explorer, F: Firefox, O: Opera.
Navigator
IE
plugins[]
Plugin
Plug-in
MIME
plugins[] IE 4 IE 4
IE 4 Plugin
Navigator
IE
appCodeName
appMinorVersion
No
No
appName
appVersion
browserLanguage
No
cookieEnabled
cookie
cpuClass
CPU
No
No
onLine
No
No
platform
systemLanguage
OS
No
No
userAgent
user-agent
userLanguage
OS
No
Navigator
IE
javaEnabled()
Java
taintEnabled()
(data tainting)
Navigator
Navigator
Netscape Navigator
JavaScript
Navigator Window navigator
appCodeName
Netscape "Mozilla"
Microsoft "Mozilla"
navigator.appCodeName
<html>
<body>
<script type="text/javascript">
document.write("<p>CodeName: ")
document.write(navigator.appCodeName + "</p>")
</script>
</body>
</html>
appMinorVersion
navigator.appMinorVersion
<html>
<body>
<script type="text/javascript">
document.write("<p>MinorVersion: ")
document.write(navigator.appMinorVersion + "</p>")
</script>
</body>
</html>
appName
appName Netscape
"Netscape" IE "Microsoft Internet Explorer"
navigator.appMinorVersion
<html>
<body>
<script type="text/javascript">
document.write("<p>Name: ")
document.write(navigator.appName + "</p>")
</script>
</body>
</html>
appVersion
parseInt()
navigator.appVersion
<html>
<body>
<script type="text/javascript">
document.write("<p>Version: ")
document.write(navigator.appVersion + "</p>")
</script>
</body>
</html>
browserLanguage
navigator.browserLanguage
<html>
<body>
<script type="text/javascript">
document.write("<p>BrowserLanguage: ")
document.write(navigator.browserLanguage + "</p>")
</script>
</body>
</html>
navigator.cookieEnabled
<html>
<body>
<script type="text/javascript">
document.write("<p>CookieEnabled: ")
document.write(navigator.cookieEnabled + "</p>")
</script>
</body>
</html>
cpuClass CPU
navigator.cpuClassd
<html>
<body>
<script type="text/javascript">
document.write("<p>CPUClass: ")
document.write(navigator.cpuClass + "</p>")
</script>
</body>
</html>
onLine
IE 4+
navigator.onLine
<html>
<body>
<script type="text/javascript">
document.write("<p>OnLine: ")
document.write(navigator.onLine + "</p>")
</script>
</body>
</html>
platform
"Win32" "MacPPC"
"Linuxi586"
navigator.platform
<html>
<body>
<script type="text/javascript">
document.write("<p>Platform: ")
document.write(navigator.platform + "</p>")
</script>
</body>
</html>
systemLanguage
navigator.systemLanguage
<html>
<body>
<script type="text/javascript">
document.write("<p>SystemLanguage: ")
document.write(navigator.systemLanguage + "</p>")
</script>
</body>
</html>
userAgent HTTP
navigator.appCodeName navigator.appVersion
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)
user-agent header
navigator.userAgent
<html>
<body>
<script type="text/javascript">
document.write("<p>UserAgent: ")
document.write(navigator.userAgent + "</p>")
</script>
</body>
</html>
userLanguage
navigator.userLanguage
<html>
<body>
<script type="text/javascript">
document.write("<p>UserLanguage: ")
document.write(navigator.userLanguage + "</p>")
</script>
</body>
</html>
javaEnabled() Java
true false
navigator.javaEnabled()
navigator.javaEnabled() Java
Java
Java
<html>
<body>
<script type="text/javascript">
alert(navigator.javaEnabled())
</script>
</body>
</html>
true
navigator.taintEnabled()
data tainting
<html>
<body>
<script type="text/javascript">
alert(navigator.taintEnabled())
</script>
</body>
</html>
false
Screen
Screen
Screen
screen
IE: Internet Explorer, F: Firefox, O: Opera.
Screen
IE
availHeight
( Windows
)
availWidth
( Windows
)
bufferDepth
No
No
colorDepth
deviceXDPI
No
No
deviceYDPI
No
No
fontSmoothingEnabled
No
No
height
logicalXDPI
No
No
logicalYDPI
No
No
pixelDepth
No
updateInterval
No
No
width
Screen
Window screen Screen Screen
JavaScript
16 8 JavaScript
availHeight Windows
screen.availHeight
<html>
<body>
<script type="text/javascript">
document.write("<p>Available Height: ")
document.write(screen.availHeight + "</p>")
</script>
</body>
</html>
availWidth Windows
screen.availWidth
<html>
<body>
<script type="text/javascript">
document.write("<p>Available Width: ")
document.write(screen.availWidth + "</p>")
</script>
</body>
</html>
screen.bufferDepth=number
<html>
<body>
<script type="text/javascript">
document.write("<p>Buffer Depth: ")
document.write(screen.bufferDepth + "</p>")
</script>
</body>
</html>
colorDepth
screen.colorDepth
<html>
<body>
<script type="text/javascript">
document.write("<p>Color Depth: ")
document.write(screen.colorDepth + "</p>")
</script>
</body>
</html>
deviceXDPI
screen.deviceXDPI
<html>
<body>
<script type="text/javascript">
document.write("<p>Device XDPI: ")
document.write(screen.deviceXDPI + "</p>")
</script>
</body>
</html>
deviceYDPI
screen.deviceYDPI
<html>
<body>
<script type="text/javascript">
document.write("<p>Device YDPI: ")
document.write(screen.deviceYDPI + "</p>")
</script>
</body>
</html>
fontSmoothingEnabled
sscreen.fontSmoothingEnabled
<html>
<body>
<script type="text/javascript">
document.write("<p>FontSmoothingEnabled: ")
document.write(screen.fontSmoothingEnabled + "</p>")
</script>
</body>
</html>
height
screen.height
<html>
<body>
<script type="text/javascript">
document.write("<p>Height: ")
document.write(screen.height + "</p>")
</script>
</body>
</html>
logicalXDPI
screen.logicalXDPI
<html>
<body>
<script type="text/javascript">
document.write("<p>Logical XDPI: ")
document.write(screen.logicalXDPI + "</p>")
</script>
</body>
</html>
logicalYDPI
screen.logicalYDPI
<html>
<body>
<script type="text/javascript">
document.write("<p>Logical YDPI: ")
document.write(screen.logicalYDPI + "</p>")
</script>
</body>
</html>
pixelDepth
screen.pixelDepth
<html>
<body>
<script type="text/javascript">
document.write("<p>Pixel Depth: ")
document.write(screen.pixelDepth + "</p>")
</script>
</body>
</html>
updateInterval
screen.updateInterval=number
<html>
<body>
<script type="text/javascript">
document.write("<p>Update Interval: ")
document.write(screen.updateInterval + "</p>")
</script>
</body>
</html>
width
screen.width
<html>
<body>
<script type="text/javascript">
document.write("<p>Width: ")
document.write(screen.width + "</p>")
</script>
</body>
</html>
History
History
History URL
History window window.history
History
IE: Internet Explorer, F: Firefox, O: Opera.
History
IE
length
URL
History
IE
back()
history URL
forward()
history URL
go()
history
History
History History
URL back()forward() go()
history.back()
history.go(-2)
length
IE 6 Opera 9 0 Firefox 1.5 1
history.length
<html>
<body>
<script type="text/javascript">
document.write(history.length);
</script>
</body>
</html>
back() URL
history.go(-1)
history.back()
<html>
<head>
<script type="text/javascript">
function goBack()
{
window.history.back()
}
</script>
</head>
<body>
<input type="button" value="Back" onclick="goBack()" />
</body>
</html>
forward() URL
history.go(1)
history.forward()
<html>
<head>
<script type="text/javascript">
function goForward()
{
window.history.forward()
}
</script>
</head>
<body>
<input type="button" value="Forward" onclick="goForward()" />
</body>
</html>
go()
history.go(number|URL)
<html>
<head>
<script type="text/javascript">
function goBack()
{
window.history.go(-1)
}
</script>
</head>
<body>
<input type="button" value="Back" onclick="goBack()" />
</body>
</html>
Location
Location
Location URL
Location Window window.location
<html>
<head>
<script type="text/javascript">
function currLocation()
{
alert(window.location)
}
function newLocation()
{
window.location="/index.html"
}
</script>
</head>
<body>
<input type="button" onclick="currLocation()" value=" URL">
Location
IE
hash
(#) URL
host
URL
hostname
URL
href
URL
pathname
URL
port
URL
protocol
URL
search
(?) URL
Location
IE
assign()
reload()
replace()
Location
Location Window Location
Web href URL URL
Anchor Area URL Location
href location
location.href
Anchor Location
URL Location
hash URL #
location.hash=anchorname
URL : http://example.com:1234/test.htm#part2
<html>
<body>
<script type="text/javascript">
document.write(location.hash);
</script>
</body>
</html>
#part2
host URL
location.host
URL : http://example.com:1234/test.htm#part2
<html>
<body>
<script type="text/javascript">
document.write(location.host);
</script>
</body>
</html>
example.com:1234
hostname URL
location.hostname
URL : http://example.com:1234/test.htm#part2
<html>
<body>
<script type="text/javascript">
document.write(location.hostname);
</script>
</body>
</html>
example.com
href URL
URL URL
location.href=URL
URL : http://example.com:1234/test.htm#part2
<html>
<body>
<script type="text/javascript">
document.write(location.href);
</script>
</body>
</html>
http://example.com:1234/test.htm#part2
pathname URL
location.pathname=path
URL : http://example.com:1234/test/test.htm#part2
<html>
<body>
<script type="text/javascript">
document.write(location.pathname);
</script>
</body>
</html>
/test/test.htm
port URL
location.port=portnumber
URL : http://example.com:1234/test.htm#part2
<html>
<body>
<script type="text/javascript">
document.write(location.port);
</script>
</body>
</html>
1234
protocol URL
location.protocol=path
URL : http://example.com:1234/test.htm#part2
<html>
<body>
<script type="text/javascript">
document.write(location.protocol);
</script>
</body>
</html>
http:
search URL ?
location.search=path_from_questionmark
URL : http://www.w3school.com.cn/tiy/t.asp?f=hdom_loc_search
<html>
<body>
<script type="text/javascript">
document.write(location.search);
</script>
</body>
</html>
?f=hdom_loc_search
assign()
location.assign(URL)
assign()
<html>
<head>
<script type="text/javascript">
function newDoc()
{
window.location.assign("http://www.w3school.com.cn")
}
</script>
</head>
<body>
reload()
location.reload(force)
true
Shift
<html>
<head>
<script type="text/javascript">
function reloadPage()
{
window.location.reload()
}
</script>
</head>
<body>
<input type="button" value="Reload page"
onclick="reloadPage()" />
</body>
</html>
replace()
location.replace(newURL)
replace()
<html>
<head>
<script type="text/javascript">
function replaceDoc()
{
window.location.replace("http://www.w3school.com.cn")
}
</script>
</head>
<body>
<input type="button" value="Replace document" onclick="replaceDoc()"
/>
</body>
</html>
Document
IE
W3C
all[]
HTML
No
anchors[]
Anchor
Yes
applets
Applet
forms[]
Form
Yes
images[]
Image
Yes
links[]
Area Link
Yes
Document
body
<body>
<frameset>
cookie
IE
W3C
cookie
Yes
domain
Yes
lastModified
No
No
referrer
URL
Yes
title
Yes
URL
URL
Yes
Document
IE
W3C
close()
document.open()
Yes
getElementById()
id
Yes
getElementsByName()
Yes
getElementsByTagName()
Yes
open()
document.write() document.writeln()
Yes
write()
HTML JavaScript
Yes
writeln()
write()
Yes
Document
HTMLDocument DOM Document HTML
HTMLCollection
0 DOM Document.getElementsByTagName()
write()
all HTML
document.all[i]
document.all[name]
document.all.tags[tagname]
all[]
all[] HTML name
id name
anchors Anchor
document.anchors[]
<html>
<body>
<a name="first">First anchor</a><br />
<a name="second">Second anchor</a><br />
<a name="third">Third anchor</a><br />
<br />
Number of anchors in this document:
<script type="text/javascript">
document.write(document.anchors.length)
</script>
</body>
</html>
forms Form
document.forms[]
<html>
<body>
<form name="Form1"></form>
<form name="Form2"></form>
<form name="Form3"></form>
<script type="text/javascript">
document.write("This document contains: ")
images Image
document.images[]
0 DOM <object>
<html>
<body>
<img border="0" src="hackanm.gif" width="48" height="48">
<br />
<img border="0" src="compman.gif" width="107" height="98">
<br /><br />
<script type="text/javascript">
document.write("This document contains: ")
document.write(document.images.length + " images.")
</script>
</body>
</html>
document.links[]
<html>
<body>
<img src="planets.gif"
width="145" height="126"
usemap="#planetmap" />
<map name="planetmap">
<area id="venus" shape="circle"
coords="124,58,8"
alt="Venus"
href="venus.htm" />
</map>
<br />
Number of links in this document:
<script type="text/javascript">
document.write(document.links.length)
</script>
</body>
</html>
cookie cookie
document.cookie
cookie
<html>
<body>
The cookies associated with this document is:
<script type="text/javascript">
document.write(document.cookie)
</script>
</body>
</html>
domain
document.domain
web
domain
<html>
<body>
The domain name for this document is:
<script type="text/javascript">
document.write(document.domain)
</script>
</body>
</html>
lastModified
document.lastModified
<html>
<body>
This document was last modified on:
<script type="text/javascript">
document.write(document.lastModified)
</script>
</body>
</html>
referrer URL
document.referrer
null JavaScript
HTTP
<html>
<body>
The referrer of this document is:
<script type="text/javascript">
document.write(document.referrer)
</script>
</body>
</html>
document.title
<html>
<head>
<title>My title</title>
</head>
<body>
The title of the document is:
<script type="text/javascript">
document.write(document.title)
</script>
</body>
</html>
URL URL
document.URL
<html>
<body>
The URL of this document is:
<script type="text/javascript">
document.write(document.URL)
</script>
</body>
</html>
close() document.open
document.close()
open()
write() close()
<html>
<head>
<script type="text/javascript">
function createNewDoc()
{
var newDoc=document.open("text/html","replace");
var txt="<html><body>Learning about the DOM is FUN!</body></html>";
newDoc.write(txt);
newDoc.close();
}
</script>
</head>
<body>
<input type="button" value="Write to a new document"
onclick="createNewDoc()">
</body>
</html>
getElementById() ID
document.getElementById(id)
1
<html>
<head>
<script type="text/javascript">
function getValue()
{
var x=document.getElementById("myHeader")
alert(x.innerHTML)
}
</script>
</head>
<body>
<h1 id="myHeader" onclick="getValue()">This is a header</h1>
<p>Click on the header to alert its value</p>
</body>
</html>
2
getElementById() DOM
getElementById()
function id(x) {
if (typeof x == "string") return document.getElementById(x);
return x;
}
ID x
= id(x)
getElementsByName()
document.getElementsByName(name)
getElementById() name id
name HTML
name
getElementsByName()
<html>
<head>
<script type="text/javascript">
function getElements()
{
var x=document.getElementsByName("myInput");
alert(x.length);
}
</script>
</head>
<body>
<input name="myInput" type="text" size="20" /><br />
<input name="myInput" type="text" size="20" /><br />
<input name="myInput" type="text" size="20" /><br />
<br />
<input type="button" onclick="getElements()"
value="How many elements named 'myInput'?" />
</body>
</html>
getElementsByTagName()
document.getElementsByTagName(tagname)
getElementsByTagName()
"*" getElementsByTagName()
getElementsByTagName()
1
<html>
<head>
<script type="text/javascript">
function getElements()
{
var x=document.getElementsByTagName("input");
alert(x.length);
}
</script>
</head>
<body>
<input name="myInput" type="text" size="20" /><br />
<input name="myInput" type="text" size="20" /><br />
<input name="myInput" type="text" size="20" /><br />
<br />
<input type="button" onclick="getElements()"
value="How many input elements?" />
</body>
</html>
2
getElementsByTagName() HTML
open()
document.open(mimetype,replace)
mimetype
"text/html"
replace
HTML write()
writeln()
open() write()
close
<html>
<head>
<script type="text/javascript">
function createNewDoc()
{
var newDoc=document.open("text/html","replace");
var txt="<html><body>Learning about the DOM is FUN!</body></html>";
newDoc.write(txt);
newDoc.close();
}
</script>
</head>
<body>
<input type="button" value="Write to a new document"
onclick="createNewDoc()">
</body>
</html>
document.write(exp1,exp2,exp3,....)
DOM write()
write() HTML
close()
<html>
<body>
<script type="text/javascript">
document.write("Hello World!");
</script>
</body>
</html>
writeln() write()
document.writeln(exp1,exp2,exp3,....)
<pre>
<html>
<body>
<script type="text/javascript">
document.writeln("Hello World!");
</script>
</body>
</html>
Document anchors[]
document.getElementById()
IE: Internet Explorer, F: Firefox, O: Opera, W3C: W3C .
Anchor
IE
W3C
accessKey
No
Yes
charset
Yes
coords
Yes
href
URL
Yes
hreflang
Yes
id
id
Yes
innerHTML
No
name
Yes
rel
URL
No
Yes
rev
URL
No
Yes
shape
Yes
tabIndex
Tab
Yes
target
Yes
type
MIME
Yes
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
Anchor
IE
W3C
blur()
Yes
focus()
Yes
Area
IE
W3C
accessKey
No
Yes
alt
Yes
coords
Yes
hash
URL
No
No
host
URL
No
No
href
URL
Yes
id
id
Yes
noHref
Yes
pathname
URL
No
protocol
URL
No
search
URL
No
shape
Yes
tabIndex
tab
Yes
target
link-URL
Yes
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
Base
IE
W3C
href
URL
Yes
id
<base> id
Yes
target
Yes
Body
IE
W3C
className
class
Yes
dir
Yes
id
body id
Yes
lang
Yes
title
Yes
Button
IE
W3C
accessKey
Yes
disabled
Yes
form
Yes
id
id
Yes
name
Yes
tabIndex
Tab
Yes
type
Yes
value
Yes
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
Canvas
height
300
width
300
Canvas
getContext()
getContext()
Canvas.getContext(contextID)
contextID "2d"
API
<canvas> 3D getContext()
"3d"
CanvasRenderingContext2D Canvas
2 3
"2d" CanvasRenderingContext2D
Form
IE
W3C
elements[]
Yes
Form
IE
W3C
acceptCharset
No
No
No
Yes
action
action
Yes
enctype
MIME
Yes
id
id
Yes
length
Yes
method
HTTP
Yes
name
Yes
target
Frame Window
Yes
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
Form
IE
W3C
reset()
Yes
submit()
Yes
Form
IE
W3C
onreset
Yes
onsubmit
Yes
Frame
IE
W3C
contentDocument
No
Yes
frameBorder
Yes
id
id
Yes
longDesc
URL
Yes
marginHeight
Yes
marginWidth
Yes
name
Yes
noResize
Yes
scrolling
No
No
Yes
src
URL
Yes
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
Frameset
IE
W3C
cols
Yes
id
id
Yes
rows
Yes
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
IFrame
IE
W3C
align
iframe
Yes
contentDocument
No
Yes
frameBorder
iframe
No
Yes
height
iframe
Yes
id
iframe id
Yes
longDesc
iframe URL
Yes
marginHeight
iframe
Yes
marginWidth
iframe
Yes
name
iframe
Yes
scrolling
iframe
No
No
Yes
src
iframe URL
Yes
iframe
width
Yes
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
Image
IE
W3C
align
Yes
alt
Yes
border
Yes
complete
No
height
Yes
hspace
Yes
id
id
Yes
isMap
Yes
longDesc
URL
Yes
lowsrc
URL
No
name
Yes
src
URL
Yes
useMap
usemap
Yes
vspace
Yes
width
Yes
IE
W3C
className
class
Yes
title
title
Yes
Image
IE
W3C
onabort
Yes
onerror
Yes
onload
Yes
Button
IE
W3C
accessKey
Yes
alt
Yes
disabled
Yes
form
Yes
id
id
Yes
name
Yes
tabIndex
tab
Yes
type
Yes
value
Yes
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
Button
IE
W3C
blur()
Yes
click()
Yes
focus()
Yes
Checkbox
IE
W3C
accessKey
checkbox
Yes
alt
checkbox
Yes
checked
checkbox
Yes
defaultChecked
checked
Yes
disabled
checkbox
Yes
form
checkbox
Yes
id
checkbox id
Yes
name
checkbox
Yes
tabIndex
checkbox tab
Yes
type
checkbox
Yes
value
checkbox value
Yes
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
Checkbox
IE
W3C
blur()
checkbox
Yes
click()
checkbox
Yes
focus()
checkbox
Yes
value file-upload
elements[] document.getElementById()
FileUpload
IE: Internet Explorer, F: Firefox, O: Opera, W3C: W3C .
FileUpload
accept
MIME
accessKey
FileUpload
alt
<input type="file">
IE
W3C
Yes
Yes
Yes
defaultValue
FileUpload
disabled
FileUpload
form
FileUpload
Yes
id
FileUpload id
Yes
name
FileUpload
Yes
tabIndex
FileUpload tab
type
FileUpload "file" 4
Yes
value
FileUpload
Yes
Yes
Yes
Yes
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
W3C
FileUpload
IE
blur()
FileUpload
Yes
focus()
FileUpload
Yes
select()
FileUpload
Yes
value
Web
Hidden
IE
W3C
alt
Yes
form
Yes
id
id
Yes
name
Yes
type
Yes
value
value
Yes
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
"text" onchange
elements[] array
document.getElementById()
IE: Internet Explorer, F: Firefox, O: Opera, W3C: W3C .
Password
IE
W3C
accessKey
Yes
alt
Yes
defaultValue
Yes
disabled
Yes
form
Yes
id
id
Yes
maxLength
Yes
name
Yes
readOnly
Yes
size
Yes
tabIndex
tab
Yes
type
Yes
value
value
Yes
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
Password
IE
W3C
blur()
Yes
focus()
Yes
select()
Yes
onclick
elements[] Radio
document.getElementById()
IE: Internet Explorer, F: Firefox, O: Opera, W3C: W3C .
Radio
IE
W3C
accessKey
Yes
alt
Yes
checked
Yes
defaultChecked
Yes
disabled
Yes
form
Yes
id
id
Yes
name
Yes
tabIndex
tab
Yes
type
Yes
value
value
Yes
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
Radio
IE
W3C
blur()
No
Yes
click()
No
Yes
focus()
No
Yes
Reset
IE
W3C
accesskey
Yes
alt
Yes
disabled
Yes
form
Yes
id
id
Yes
name
Yes
tabIndex
tab
Yes
type
Yes
value
Yes
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
Reset
IE
W3C
blur()
Yes
click()
Yes
focus()
Yes
Form.submit() Form.onsubmit
elements[]
document.getElementById()
IE: Internet Explorer, F: Firefox, O: Opera, W3C: W3C .
Submit
IE
W3C
accessKey
Yes
alt
Yes
disabled
Yes
form
Yes
id
id
Yes
name
Yes
tabIndex
tab
Yes
type
Yes
value
Yes
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
Submit
IE
W3C
blur()
Yes
click()
Yes
focus()
Yes
onchange
HTML <textarea> Textarea
<input type="text"> type "password" Input
Password
elements[]
document.getElementById()
IE: Internet Explorer, F: Firefox, O: Opera, W3C: W3C .
Text
IE
W3C
accessKey
Yes
alt
Yes
defaultValue
Yes
disabled
Yes
form
Yes
id
id
Yes
maxLength
Yes
name
Yes
readOnly
Yes
size
Yes
tabIndex
tab
Yes
type
Yes
value
value
Yes
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
Text
IE
W3C
blur()
Yes
focus()
Yes
select()
Yes
Link
IE
W3C
charset
URL
Yes
disabled
URL
Yes
href
URL
Yes
hreflang
URL
Yes
id
<link> id
Yes
media
Yes
name
<link>
No
No
Yes
rel
URL
Yes
rev
URL
Yes
type
URL MIME
Yes
IE
W3C
dir
Yes
lang
Yes
Meta
IE
W3C
content
<meta> content
Yes
httpEquiv
content HTTP
Yes
name
content
Yes
scheme
content
Yes
metaObject.content=text
<meta> content
<html>
<head>
<meta name="keywords" content="HTML,DHTML,CSS,JavaScript" />
</head>
<body>
<script type="text/javascript">
x=document.getElementsByTagName("meta")[0];
document.write("Meta content: " + x.content);
</script>
</body>
</html>
metaObject.httpEquiv=content-type|expires|refresh|set-cookie
5
<html>
<head>
<meta http-equiv="refresh" content="5" />
</head>
<body>
<script type="text/javascript">
x=document.getElementsByTagName("meta")[0];
document.write("Http equiv: " + x.httpEquiv);
</script>
</body>
</html>
scheme content
metaObject.scheme=format
content
<html>
<head>
<meta name="revised" content="2006-11-03" scheme="YYYY-MM-DD" />
</head>
<body>
<script type="text/javascript">
x=document.getElementsByTagName("meta")[0];
document.write("Content format: " + x.scheme);
</script>
</body>
</html>
Object
W3C
align
Yes
archive
Yes
border
Yes
code
URL Java
Yes
codeBase
URL
Yes
codeType
Yes
data
Yes
declare
Yes
form
Yes
height
Yes
hspace
Yes
name
Yes
standby
Yes
type
data
Yes
useMap
Yes
vspace
Yes
width
Yes
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
Option
IE
W3C
defaultSelected
selected
Yes
disabled
Yes
form
<form>
Yes
id
id
Yes
index
Yes
label
selected
selected
Yes
text
Yes
value
Yes
Yes
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
Select
IE
W3C
options[]
Yes
Select
IE
W3C
disabled
Yes
form
Yes
id
id
Yes
length
Yes
multiple
Yes
name
Yes
selectedIndex
Yes
size
Yes
tabIndex
tab
Yes
type
Yes
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
Select
IE
W3C
add()
Yes
blur()
Yes
focus()
Yes
remove()
Yes
Select
IE
W3C
onchange
Yes
Table
IE
W3C
cells[]
No
rows[]
Yes
tBodies[]
tbody
cells
tableObject.cells[]
cells
<html>
Yes
<head>
<script type="text/javascript">
function cell()
{
var x=document.getElementById('myTable').rows[0].cells;
alert(x[0].innerHTML);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>cell 1</td>
<td>cell 2</td>
</tr>
<tr>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</table>
<br />
<input type="button" onclick="cell()" value="Alert first cell">
</body>
</html>
tableObject.rows[]
rows
<html>
<head>
<script type="text/javascript">
function showRow()
{
alert(document.getElementById('myTable').rows[0].innerHTML)
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>Row1 cell1</td>
<td>Row1 cell2</td>
</tr>
<tr>
<td>Row2 cell1</td>
<td>Row2 cell2</td>
</tr>
</table>
<br />
<input type="button" onclick="showRow()" value="Show innerHTML">
</body>
</html>
Table
IE
W3C
align
bgColor
border
Yes
caption
<caption>
Yes
cellPadding
Yes
cellSpacing
Yes
frame
Yes
id
id
Yes
rules
Yes
summary
Yes
tFoot
TFoot null 4
Yes
tHead
THead
null
Yes
width
Yes
caption caption
<caption> <caption> <table>
captioncaption
tableObject.caption=captionObject
<caption>
<html>
<head>
<script type="text/javascript">
function alertCaption()
{
alert(document.getElementById("table1").caption.innerHTML);
}
</script>
</head>
<body>
<table id="table1" border="1">
<caption>This is a table caption</caption>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
</table>
<br />
<input type="button" onclick=alertCaption()
value="Alert table caption" />
</body>
</html>
cellPadding
tableObject.cellPadding=pixels
</tr>
</table>
<br />
<input type="button" onclick="padding()" value="Change Cellpadding">
</body>
</html>
cellSpacing
tableObject.cellSpacing=pixels
cellSpacing
<html>
<head>
<script type="text/javascript">
function spacing()
{
document.getElementById('myTable').cellSpacing="15"
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>100</td>
<td>200</td>
</tr>
<tr>
<td>300</td>
<td>400</td>
</tr>
</table>
<br />
<input type="button" onclick="spacing()" value="Change Cellspacing">
</body>
</html>
frame
tableObject.frame=void|above|below|hsides|vsides|lhs|rhs|box|bord
er
<html>
<head>
<script type="text/javascript">
function aboveFrames()
{
document.getElementById('myTable').frame="above"
}
function belowFrames()
{
document.getElementById('myTable').frame="below"
}
</script>
</head>
<body>
<table id="myTable">
<tr>
<td>100</td>
<td>200</td>
</tr>
<tr>
<td>300</td>
<td>400</td>
</tr>
</table>
<br />
<input type="button" onclick="aboveFrames()"
value="Show above frames">
<input type="button" onclick="belowFrames()"
value="Show below frames">
</body>
</html>
rules
tableObject.rules=none|groups|rows|cols|all
<html>
<head>
<script type="text/javascript">
function rowRules()
{
document.getElementById('myTable').rules="rows"
}
function colRules()
{
document.getElementById('myTable').rules="cols"
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>Row1 cell1</td>
<td>Row1 cell2</td>
</tr>
<tr>
<td>Row2 cell1</td>
<td>Row2 cell2</td>
</tr>
<tr>
<td>Row3 cell1</td>
<td>Row3 cell2</td>
</tr>
</table>
<br />
<input type="button"
value="Show only row
<input type="button"
value="Show only col
onclick="rowRules()"
borders">
onclick="colRules()"
borders">
</body>
</html>
summary
summary
tableObject.summary=text
<html>
<head>
<script type="text/javascript">
function alertSummary()
{
alert(document.getElementById("table1").summary);
}
</script>
</head>
<body>
<table id="table1" border="1"
summary="Example table of employees">
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
</table>
<br />
<input type="button" onclick=alertSummary()
value="Alert table summary" />
</body>
</html>
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
Table
IE
W3C
createCaption()
caption
Yes
createTFoot()
tFoot
Yes
createTHead()
tHead
Yes
deleteCaption()
caption
Yes
deleteRow()
Yes
deleteTFoot()
tFoot
Yes
deleteTHead()
tHead
Yes
insertRow()
Yes
createCaption() <caption>
tableObject.createCaption()
HTMLElement <caption>
<caption> <caption>
<html>
<head>
<script type="text/javascript">
function createCaption()
{
var x=document.getElementById('myTable').createCaption()
x.innerHTML="My table caption"
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>Row1 cell1</td>
<td>Row1 cell2</td>
</tr>
<tr>
<td>Row2 cell1</td>
<td>Row2 cell2</td>
</tr>
</table>
<br />
<input type="button" onclick="createCaption()"
value="Create caption">
</body>
</html>
createTFoot() <tfoot>
tableObject.createTFoot()
TableSection <tfoot>
<tfoot>
<html>
<head>
<script type="text/javascript">
function createCaption()
{
var x=document.getElementById('myTable').createTFoot()
x.innerHTML="My table foot"
}
</script>
</head>
<body>
createTHead() <thead>
tableObject.createTHead()
TableSection <thead>
<thead>
<html>
<head>
<script type="text/javascript">
function createCaption()
{
var x=document.getElementById('myTable').createTHead()
deleteCaption() caption
tableObject.deleteCaption()
<caption>
<html>
<head>
<script type="text/javascript">
function deleteCaption()
{
document.getElementById('myTable').deleteCaption()
}
</script>
</head>
<body>
<table id="myTable" border="1">
<caption>My table caption</caption>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
</table>
<br />
<input type="button" onclick="deleteCaption()"
value="Delete caption" />
</body>
</html>
deleteRow()
tableObject.deleteRow(index)
index
<thead> <tfoot>
deleteTFoot() <tfoot>
tableObject.deleteTFoot()
<tfoot>
<html>
<head>
<script type="text/javascript">
function delRow()
{
document.getElementById('myTable').deleteTFoot()
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>Row1 cell1</td>
<td>Row1 cell2</td>
</tr>
<tr>
<td>Row2 cell1</td>
<td>Row2 cell2</td>
</tr>
<tfoot><td>my table foot</td></tfoot>
</table>
<br />
<input type="button" onclick="delRow()"
value="Delete table foot">
</body>
</html>
deleteTHead() <thead>
tableObject.deleteTHead()
<thead>
<html>
<head>
<script type="text/javascript">
function delRow()
{
document.getElementById('myTable').deleteTHead()
}
</script>
</head>
<body>
<table id="myTable" border="1">
<thead><td>my table head</td></thead>
<tr>
<td>Row1 cell1</td>
<td>Row1 cell2</td>
</tr>
<tr>
<td>Row2 cell1</td>
<td>Row2 cell2</td>
</tr>
</table>
<br />
<input type="button" onclick="delRow()"
value="Delete table foot">
</body>
</html>
insertRow()
tableObject.insertRow(index)
TableRow
TableRow <tr>
index index
<tbody>
index 0 INDEX_SIZE_ERR
DOMException
TableRow.insertCell()
<html>
<head>
<script type="text/javascript">
function insRow()
{
document.getElementById('myTable').insertRow(0)
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>Row1 cell1</td>
<td>Row1 cell2</td>
</tr>
<tr>
<td>Row2 cell1</td>
<td>Row2 cell2</td>
</tr>
</table>
<br />
<input type="button" onclick="insRow()"
value="Insert new row">
</body>
</html>
TableCell
IE
W3C
abbr
Yes
align
Yes
axis
Yes
cellIndex
Yes
ch
Yes
chOff
Yes
colSpan
headers
header-cell id
id
id
Yes
Yes
Yes
innerHTML
No
Yes
HTML
rowSpan
scope
vAlign
Yes
width
Yes
Yes
abbr
tabledataObject.abbr=text
abbr
<html>
<head>
<script type="text/javascript">
function alertAbbr()
{
alert(document.getElementById('td1').abbr);
}
</script>
</head>
<body>
<table border="1">
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td id="td1" abbr="Some text">Peter</td>
<td id="td2">Griffin</td>
</tr>
</table>
<br />
<input type="button" onclick="alertAbbr()"
value="Alert abbr" />
</body>
</html>
axis
axis
tabledataObject.axis=text
axis
<html>
<head>
<script type="text/javascript">
function alertAxis()
{
alert(document.getElementById('td3').axis);
}
</script>
</head>
<body>
<table border="1">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>City</th>
</tr>
<tr>
<td id="td1">Harry</td>
<td id="td2">Potter</td>
<td id="td3" axis="location">NY</td>
</tr>
<tr>
<td id="td4">Peter</td>
<td id="td5">Griffin</td>
<td id="td6" axis="location">Las Vegas</td>
</tr>
</table>
<br />
<input type="button" onclick="alertAxis()"
value="Alert axis" />
</body>
</html>
cellIndex
tabledataObject.cellIndex
cell index
<html>
<head>
<script type="text/javascript">
function alertTd1()
{
alert(document.getElementById('td1').cellIndex);
}
function alertTd2()
{
alert(document.getElementById('td2').cellIndex);
}
</script>
</head>
<body>
<table border="1">
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td id="td1">Peter</td>
<td id="td2">Griffin</td>
</tr>
</table>
<br />
<input type="button" onclick="alertTd1()"
value="Alert cell index of 'Peter'" />
<br />
<input type="button" onclick="alertTd2()"
value="Alert cell index of 'Griffin'" />
</body>
</html>
colSpan
tabledataObject.colSpan=number_of_columns
<html>
<head>
<script type="text/javascript">
function changeColSpan()
{
document.getElementById("td1").colSpan="2";
}
</script>
</head>
<body>
<table border="1">
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td id="td1">Peter</td>
<td id="td2">Griffin</td>
</tr>
</table>
<br />
<input type="button" onclick=changeColSpan()
value="Change colspan" />
</body>
</html>
rowSpan
tabledataObject.rowSpan=number_of_rows
<html>
<head>
<script type="text/javascript">
function changeRowSpan()
{
document.getElementById("td2").rowSpan="2";
}
</script>
</head>
<body>
<table border="1">
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td id="td1">Peter</td>
<td id="td2">Griffin</td>
</tr>
<tr>
<td id="td3">Harry</td>
<td id="td4">Potter</td>
</tr>
</table>
<br />
<input type="button" onclick=changeRowSpan()
value="Change rowspan" />
</body>
</html>
vAlign
tabledataObject.vAlign=top|middle|bottom|baseline
<html>
<head>
<script type="text/javascript">
function topAlign()
{
document.getElementById('td1').vAlign="top";
document.getElementById('td2').vAlign="top";
document.getElementById('td3').vAlign="top";
}
</script>
</head>
<body>
<table width="50%" border="1">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Text</th>
</tr>
<tr>
<td id="td1">Peter</td>
<td id="td2">Griffin</td>
<td id="td3">Hello my name is Peter Griffin.
I need a long text for this example.
I need a long text for this example.</td>
</tr>
</table>
<br />
<input type="button" onclick="topAlign()"
value="Top-align table cells" />
</body>
</html>
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
TableRow
IE
W3C
cells[]
Yes
TableRow
IE
W3C
align
Yes
ch
Yes
chOff
Yes
id
id
Yes
innerHTML
HTML
No
rowIndex
Yes
sectionRowIndex
vAlign
Yes
4
Yes
tablerowObject.rowIndex
<html>
<head>
<script type="text/javascript">
function alertRowIndex()
{
alert(document.getElementById("tr1").rowIndex);
}
</script>
</head>
<body>
<table border="1">
<tr id="tr1">
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr id="tr2">
<td>Peter</td>
<td>Griffin</td>
</tr>
</table>
<br />
<input type="button" onclick="alertRowIndex()"
value="Alert row index" />
</body>
</html>
vAlign
tablerowObject.vAlign=top|bottom|middle|baseline
<html>
<head>
<script type="text/javascript">
function topAlign()
{
document.getElementById('tr2').vAlign="top";
}
</script>
</head>
<body>
<table width="50%" border="1">
<tr id="tr1">
<th>Firstname</th>
<th>Lastname</th>
<th>Text</th>
</tr>
<tr id="tr2">
<td>Peter</td>
<td>Griffin</td>
<td>Hello my name is Peter Griffin.
I need a long text for this example.
I need a long text for this example.</td>
</tr>
</table>
<br />
<input type="button" onclick="topAlign()"
value="Top-align table row" />
</body>
</html>
TableRow
IE
W3C
deleteCell()
Yes
insertCell()
<td>
Yes
deleteCell() <td>
tablerowObject.deleteCell(index)
index
index 0 INDEX_SIZE_ERR
DOMException
<html>
<head>
<script type="text/javascript">
function delCell()
{
document.getElementById('tr2').deleteCell(0)
}
</script>
</head>
<body>
<table border="1">
<tr id="tr1">
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr id="tr2">
<td>Peter</td>
<td>Griffin</td>
</tr>
</table>
<br />
<input type="button" onclick="delCell()" value="Delete cell">
</body>
</html>
tablerowObject.insertCell(index)
TableCell <td>
<td>
index index
<td>
Document.createElement() Node.insertBefore()
<th>
index 0 INDEX_SIZE_ERR
DOMException
<html>
<head>
<script type="text/javascript">
function insCell()
{
var x=document.getElementById('tr2').insertCell(0)
x.innerHTML="John"
}
</script>
</head>
<body>
<table border="1">
<tr id="tr1">
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr id="tr2">
<td>Peter</td>
<td>Griffin</td>
</tr>
</table>
<br />
<input type="button" onclick="insCell()" value="Insert cell">
</body>
</html>
IE
W3C
accessKey
textarea
Yes
cols
textarea
Yes
defaultValue
Yes
disabled
textarea
Yes
form
textarea
Yes
id
textarea id
Yes
name
textarea
Yes
readOnly
textarea
Yes
rows
textarea
Yes
tabIndex
textarea tab
Yes
type
Yes
value
textarea
Yes
IE
W3C
className
class
Yes
dir
Yes
lang
Yes
title
title
Yes
Textarea
IE
W3C
blur()
textarea
Yes
focus()
textarea
Yes
select()
textarea
Yes
Textarea
IE
W3C
onchange
Ye
Style
IE: Internet Explorer, M: Mac IE, W: Windows IE, F: Firefox, O: Opera
W3C: World Wide Web Consortium (Internet ).
Background
IE
W3C
background
Yes
backgroundAttachment
Yes
backgroundColor
Yes
backgroundImage
Yes
backgroundPosition
No
No
Yes
backgroundPositionX
backgroundPosition X
No
No
No
backgroundPositionY
backgroundPosition Y
No
No
No
backgroundRepeat
Yes
Border Margin
IE
W3C
border
Yes
borderBottom
Yes
borderBottomColor
Yes
borderBottomStyle
Yes
borderBottomWidth
Yes
borderColor
()
Yes
borderLeft
Yes
borderLeftColor
Yes
borderLeftStyle
Yes
borderLeftWidth
Yes
borderRight
Yes
borderRightColor
Yes
borderRightStyle
Yes
borderRightWidth
Yes
borderStyle
()
Yes
borderTop
Yes
borderTopColor
Yes
borderTopStyle
Yes
borderTopWidth
Yes
borderWidth
()
Yes
margin
()
Yes
marginBottom
Yes
marginLeft
Yes
marginRight
Yes
marginTop
Yes
outline
outline
5M
Yes
outlineColor
5M
Yes
outlineStyle
5M
Yes
outlineWidth
5M
Yes
padding
()
Yes
paddingBottom
Yes
paddingLeft
Yes
paddingRight
Yes
paddingTop
Yes
Layout
IE
W3C
clear
Yes
clip
Yes
content
5M
Yes
counterIncrement
5M
Yes
counterReset
5M
Yes
cssFloat
5M
Yes
cursor
Yes
direction
Yes
display
Yes
height
Yes
markerOffset
5M
Yes
marks
5M
Yes
maxHeight
5M
Yes
maxWidth
5M
Yes
minHeight
5M
Yes
minWidth
5M
Yes
overflow
Yes
verticalAlign
No
Yes
visibility
Yes
width
Yes
List
IE
W3C
listStyle
Yes
listStyleImage
No
Yes
listStylePosition
Yes
listStyleType
Yes
Positioning
IE
W3C
bottom
Yes
left
Yes
position
Yes
right
Yes
top
Yes
zIndex
Yes
Printing
IE
W3C
orphans
5M
Yes
page
5M
Yes
pageBreakAfter
Yes
pageBreakBefore
Yes
pageBreakInside
5M
Yes
size
Yes
widows
Yes
5M
Scrollbar (IE-only)
IE
W3C
scrollbar3dLightColor
5W
No
No
No
scrollbarArrowColor
5W
No
No
No
scrollbarBaseColor
5W
No
No
No
scrollbarDarkShadowColor
5W
No
No
No
scrollbarFaceColor
5W
No
No
No
scrollbarHighlightColor
5W
No
No
No
scrollbarShadowColor
5W
No
No
No
scrollbarTrackColor
5W
No
No
No
Table
IE
W3C
borderCollapse
HTML
Yes
borderSpacing
5M
Yes
captionSide
5M
No
No
Yes
emptyCells
5M
Yes
tableLayout
No
No
Yes
IE
W3C
color
Yes
font
Yes
fontFamily
Yes
fontSize
Yes
fontSizeAdjust
5M
No
Yes
fontStretch
5M
No
No
Yes
fontStyle
Yes
fontVariant
Yes
fontWeight
Yes
letterSpacing
Yes
lineHeight
Yes
quotes
5M
textAlign
Yes
textDecoration
Yes
Text
Yes
textIndent
textShadow
5M
textTransform
unicodeBidi
Yes
Yes
Yes
Yes
whiteSpace
Yes
wordSpacing
Yes
IE
W3C
dir
Yes
lang
Yes
title
Yes
cssText
CSS
SYNTAX_ERR DOMException
CSS2Properties
NO_MODIFICATION_ALLOWED_ERR DOMException
CSS2Properties
CSS2Properties CSS CSS CSS
JavaScript
HTMLElement style CSS2Properties CSSRule
style Window.getComputedStyle() CSS2Properties
background
Object.style.background=background-color background-image
background-repeat background-attachment background-position
background-color
background-image
background-repeat
background-attachment
background-position
color-name
color-rgb
color-hex
transparent
url(URL)
none
repeat
repeat-x
repeat-y
no-repeat
scroll
fixed
top left
top center
top right
center left
center center
center right
bottom left
bottom center
bottom right
x% y%
xpos ypos
<html>
<head>
<script type="text/javascript">
function setStyle()
{
document.body.style.background="#FFCC80 url(bgdesert.jpg)
repeat-y";
}
</script>
</head>
<body>
<input type="button" onclick="setStyle()"
value="Set background style" />
</body>
</html>
TIY
<html>
<head>
<script type="text/javascript">
function setStyle()
{
document.body.style.background="#FFCC80 url(/i/eg_bg_desert.jpg)
repeat-y";
}
</script>
</head>
<body>
<input type="button" onclick="setStyle()" value="Set background
style" />
</body>
</html>
backgroundAttachment
Object.style.backgroundAttachment=scroll|fixed
<html>
<head>
<style type="text/css">
body
{
background-color="#FFCC80";
background-image:url(bgdesert.jpg);
}
p
{
color:white;
}
</style>
<script type="text/javascript">
function changeAttachment()
{
document.body.style.backgroundAttachment="fixed";
}
</script>
</head>
<body>
<input type="button" onclick="changeAttachment()"
value="Set background-image to be fixed" />
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
</body>
</html>
TIY
<html>
<head>
<style type="text/css">
body
{
background-color="#FFCC80";
background-image:url(/i/eg_bg_desert.jpg);
}
p
{
color:white;
}
</style>
<script type="text/javascript">
function changeAttachment()
{
document.body.style.backgroundAttachment="fixed";
}
</script>
</head>
<body>
<input type="button" onclick="changeAttachment()" value="Set
background-image to be fixed" />
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
<p>This is a paragraph</p>
</body>
</html>
backgroundColor
Object.style.backgroundColor=color-name|color-rgb
|color-hex|transparent
body
<html>
<head>
<style type="text/css">
body
{
background-color:#B8BFD8;
}
</style>
<script type="text/javascript">
function changeStyle()
{
document.body.style.backgroundColor="#FFCC80";
}
</script>
</head>
<body>
<input type="button" onclick="changeStyle()"
value="Change background color" />
</body>
</html>
TIY
<html>
<head>
<style type="text/css">
body
{
background-color:#B8BFD8;
}
</style>
<script type="text/javascript">
function changeStyle()
{
document.body.style.backgroundColor="#FFCC80";
}
</script>
</head>
<body>
<input type="button" onclick="changeStyle()" value="Change
background color" />
</body>
</html>
<html>
<head>
<style type="text/css">
body
{
background-color:#B8BFD8;
}
</style>
<script type="text/javascript">
function changeStyle()
{
document.body.style.backgroundColor="red";
}
</script>
</head>
<body>
<input type="button" onclick="changeStyle()" value="Change
background color" />
</body>
</html>
backgroundImage
Object.style.backgroundImage=url(URL)|none
url(URL)
none
<html>
<head>
<script type="text/javascript">
function changeStyle()
{
document.body.style.backgroundColor="#FFCC80";
document.body.style.backgroundImage="url(bgdesert.jpg)";
}
</script>
</head>
<body>
<input type="button" onclick="changeStyle()"
TIY
<html>
<head>
<script type="text/javascript">
function changeStyle()
{
document.body.style.backgroundColor="#FFCC80";
document.body.style.backgroundImage="url(/i/eg_bg_desert.jpg)";
}
</script>
</head>
<body>
<input type="button" onclick="changeStyle()" value="Set
background-image" />
</body>
</html>
backgroundPosition
Object.style.backgroundPosition=position
top left
top center
top right
center left
center center
center right
bottom left
bottom center
bottom right
"center"
0% 0%
x% y%
0% 0% 100% 100%
50%
xpos ypos
<html>
<head>
<style type="text/css">
body
{
background-color:#FFCC80;
background-image:url(bgdesert.jpg);
background-repeat:no-repeat
}
</style>
<script type="text/javascript">
function changePosition()
{
document.body.style.backgroundPosition="bottom center";
}
</script>
</head>
<body>
<input type="button" onclick="changePosition()"
value="Change background-image position" />
</body>
</html>
TIY
<html>
<head>
<style type="text/css">
body
{
background-color:#FFCC80;
background-image:url(/i/eg_bg_desert.jpg);
background-repeat:no-repeat;
background-attachment:fixed;
}
</style>
<script type="text/javascript">
function changePosition()
{
document.body.style.backgroundPosition="bottom center";
}
</script>
</head>
<body>
<input type="button" onclick="changePosition()" value="Change
background-image position" />
<p><b>Note:</b> For this to work in Mozilla, the background-attachment
property must be set to "fixed".</p>
</body>
</html>
backgroundPositionX
Object.style.backgroundPositionX=position
left
center
right
x%
0% 100%
xpos
0 (0px) CSS
<html>
<head>
<style type="text/css">
body
{
background-color:#FFCC80;
background-image:url(bgdesert.jpg);
background-repeat:no-repeat
}
</style>
<script type="text/javascript">
function changePosition()
{
document.body.style.backgroundPositionX="right";
}
</script>
</head>
<body>
<input type="button" onclick="changePosition()"
value="Change background-image's x-position" />
</body>
</html>
TIY
<html>
<head>
<style type="text/css">
body
{
background-color:#FFCC80;
background-image:url(/i/eg_bg_desert.jpg);
background-repeat:no-repeat;
background-attachment:fixed;
}
</style>
<script type="text/javascript">
function changePosition()
{
document.body.style.backgroundPositionX="right";
}
</script>
</head>
<body>
<input type="button" onclick="changePosition()" value="Change
background-image's x-position" />
<p><b>Note:</b> For this to work in Mozilla, the background-attachment
property must be set to "fixed".</p>
</body>
</html>
backgroundPositionY background-image
Object.style.backgroundPositionY=position
top
center
bottom
y%
ypos
background-image
<html>
<head>
<style type="text/css">
body
{
background-color:#FFCC80;
background-image:url(bgdesert.jpg);
background-repeat:no-repeat
}
</style>
<script type="text/javascript">
function changePosition()
{
document.body.style.backgroundPositionY="bottom";
}
</script>
</head>
<body>
<input type="button" onclick="changePosition()"
value="Change background-image's y-position" />
</body>
</html>
TIY
background-image
<html>
<head>
<style type="text/css">
body
{
background-color:#FFCC80;
background-image:url(/i/eg_bg_desert.jpg);
background-repeat:no-repeat;
background-attachment:fixed;
}
</style>
<script type="text/javascript">
function changePosition()
{
document.body.style.backgroundPositionY="bottom";
}
</script>
</head>
<body>
<input type="button" onclick="changePosition()" value="Change
background-image's y-position" />
<p><b>Note:</b> For this to work in Mozilla, the background-attachment
property must be set to "fixed".</p>
</body>
</html>
backgroundRepeat
Object.style.backgroundRepeat=repeat_value
repeat
repeat-x
repeat-y
no-repeat
y
<html>
<head>
<style type="text/css">
body
{
background-color:#FFCC80;
background-image:url(bgdesert.jpg);
}
</style>
<script type="text/javascript">
function changeRepeat()
{
document.body.style.backgroundRepeat="repeat-y";
}
</script>
</head>
<body>
TIY
background-image repeat
<html>
<head>
<style type="text/css">
body
{
background-color:#FFCC80;
background-image:url(/i/eg_bg_desert.jpg);
}
</style>
<script type="text/javascript">
function changeRepeat()
{
document.body.style.backgroundRepeat="repeat-y";
}
</script>
</head>
<body>
<input type="button" onclick="changeRepeat()" value="Repeat
background-image only on the y-axis" />
</body>
</html>
border
borderWidth
borderStyle
borderColor
<html>
<head>
<style type="text/css">
thin
medium
thick
length
none
hidden
dotted
dashed
solid
double
groove
ridge
inset
outset
color-name
color-rgb
color-hex
transparent
p
{
border: thin dotted #FF0000
}
</style>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("p1").style.border="thick solid #0000FF";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorder()"
value="Change border" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
border -
<html>
<head>
<style type="text/css">
p
{
border: thin dotted #FF0000;
}
</style>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("p1").style.border="thick solid #0000FF";
}
</script>
</head>
<body>
borderBottom
borderWidth
borderStyle
borderColor
thin
medium
thick
length
none
hidden
dotted
dashed
solid
double
groove
ridge
inset
outset
color-name
color-rgb
color-hex
transparent
<html>
<head>
<style type="text/css">
p {border: thin dotted #FF0000}
</style>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("p1").style.borderBottom="thick solid
blue";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorder()"
value="Change bottom paragraph border" />
<p id="p1">This is a paragraph with a border</p>
</body>
</html>
TIY
borderBottom -
<html>
<head>
<style type="text/css">
p
{
border: thin dotted #FF0000;
}
</style>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("p1").style.borderBottom="thick solid
blue";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorder()" value="Change bottom
border" />
<p id="p1">This is a paragraph with a border</p>
</body>
</html>
borderBottomColor
Object.style.borderBottomColor=color-name|color-rgb|color-hex
<html>
<head>
<style type="text/css">
p {border: thick solid #FF0000}
</style>
<script type="text/javascript">
function changeBorderColor()
{
document.getElementById("p1").style.borderBottomColor="blue";
}
</script>
</head>
<body>
TIY
borderBottomColor -
<html>
<head>
<style type="text/css">
p
{
border: thick solid #FF0000;
}
</style>
<script type="text/javascript">
function changeBorderColor()
{
document.getElementById("p1").style.borderBottomColor="blue";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorderColor()" value="Change
border color" />
<p id="p1">This is a paragraph</p>
</body>
</html>
borderBottomStyle
Object.style.borderBottomStyle=style
none
hidden
"none" hidden
dotted
dashed
solid
double
border-width
groove
3D border-color
ridge
3D border-color
inset
3D inset border-color
outset
3D outset border-color
<html>
<head>
<style type="text/css">
p
{
border: thick solid #FF0000
}
</style>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("p1").style.borderBottomStyle="dotted";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorder()"
value="Change bottom border" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
borderBottomStyle -
<html>
<head>
<style type="text/css">
p
{
border: thick solid #FF0000;
}
</style>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("p1").style.borderBottomStyle="dotted";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorder()" value="Change bottom
border" />
<p id="p1">This is a paragraph</p>
</body>
</html>
borderBottomWidth
Object.style.borderBottomWidth=thin|medium|thick|length
thin
medium
thick
length
<html>
<head>
<style type="text/css">
p
{
border: thin solid #FF0000
}
</style>
<script type="text/javascript">
function changeBorderWidth()
{
document.getElementById("p1").style.borderBottomWidth="thick";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorderWidth()"
value="Change bottom border" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
borderBottomWidth -
<html>
<head>
<style type="text/css">
p
{
border: thin solid #FF0000;
}
</style>
<script type="text/javascript">
function changeBorderWidth()
{
document.getElementById("p1").style.borderBottomWidth="thick";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorderWidth()" value="Change
bottom border" />
<p id="p1">This is a paragraph</p>
</body>
</html>
borderColor
1 4
table {border-color: red} -
table {border-color: red green} -
Object.style.borderColor=color-name|color-rgb|color-hex|transpare
nt
<html>
<head>
<style type="text/css">
p
{
border: thick solid #FF0000
}
</style>
<script type="text/javascript">
function changeBorderColor()
{
document.getElementById("p1").style.borderColor="#0000FF #00FF00";
}
</script>
</head>
<body>
TIY
borderColor -
<html>
<head>
<style type="text/css">
p
{
border: thick solid #FF0000;
}
</style>
<script type="text/javascript">
function changeBorderColor()
{
document.getElementById("p1").style.borderColor="#0000FF #00FF00";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorderColor()" value="Change
border color" />
<p id="p1">This is a paragraph</p>
</body>
</html>
borderLeft
borderWidth
borderStyle
borderColor
<html>
thin
medium
thick
length
none
hidden
dotted
dashed
solid
double
groove
ridge
inset
outset
color-name
color-rgb
color-hex
transparent
<head>
<style type="text/css">
p
{
border: thin dotted #FF0000
}
</style>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("p1").style.borderLeft="thick solid
#0000FF";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorder()"
value="Change left border" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
borderLeft -
<html>
<head>
<style type="text/css">
p
{
border: thin dotted #FF0000;
}
</style>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("p1").style.borderLeft="thick solid
#0000FF";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorder()" value="Change left
border" />
<p id="p1">This is a paragraph</p>
</body>
</html>
borderLeftColor
Object.style.borderLeftColor=color-name|color-rgb|color-hex|trans
parent
<html>
<head>
<style type="text/css">
p
{
border: thick solid #FF0000
}
</style>
<script type="text/javascript">
function changeBorderColor()
{
document.getElementById("p1").style.borderLeftColor="#0000FF";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorderColor()"
value="Change left border" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
borderleftColor -
<html>
<head>
<style type="text/css">
p
{
border: thick solid #FF0000;
}
</style>
<script type="text/javascript">
function changeBorderColor()
{
document.getElementById("p1").style.borderLeftColor="#0000FF";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorderColor()" value="Change
left border" />
<p id="p1">This is a paragraph</p>
</body>
</html>
borderLeftStyle
Object.style.borderLeftStyle=style
none
hidden
"none" hidden
dotted
dashed
solid
double
border-width
groove
3D border-color
ridge
3D border-color
inset
3D inset border-color
outset
3D outset border-color
<html>
<head>
<style type="text/css">
p
{
TIY
borderLeftStyle -
<html>
<head>
<style type="text/css">
p
{
border: thick solid #FF0000;
}
</style>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("p1").style.borderLeftStyle="dotted";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorder()" value="Change left
border" />
borderLeftWidth
Object.style.borderLeftWidth=thin|medium|thick|length
thin
medium
thick
length
<html>
<head>
<style type="text/css">
p
{
border: thin solid #FF0000;
}
</style>
<script type="text/javascript">
function changeBorderWidth()
{
document.getElementById("p1").style.borderLeftWidth="thick";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorderWidth()"
value="Change left border" />
<p id="p1">This is a paragraph</p>
</body>
</html>
borderRight
borderWidth
borderStyle
thin
medium
thick
length
none
hidden
dotted
dashed
borderColor
solid
double
groove
ridge
inset
outset
color-name
color-rgb
color-hex
transparent
<html>
<head>
<style type="text/css">
p
{
border: thin dotted #FF0000
}
</style>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("p1").style.borderRight="thick solid
#0000FF";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorder()"
value="Change right border" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
borderRight -
<html>
<head>
<style type="text/css">
p
{
border: thin dotted #FF0000;
}
</style>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("p1").style.borderRight="thick solid
#0000FF";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorder()" value="Change right
border" />
<p id="p1">This is a paragraph</p>
</body>
</html>
borderRightColor
Object.style.borderRightColor=color-name|color-rgb|color-hex|tran
sparent
<html>
<head>
<style type="text/css">
p
{
border: thick solid #FF0000;
}
</style>
<script type="text/javascript">
function changeBorderColor()
{
document.getElementById("p1").style.borderRightColor="#0000FF";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorderColor()"
value="Change right border" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
borderRightColor -
<html>
<head>
<style type="text/css">
p
{
border: thick solid #FF0000;
}
</style>
<script type="text/javascript">
function changeBorderColor()
{
document.getElementById("p1").style.borderRightColor="#0000FF";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorderColor()" value="Change
right border" />
<p id="p1">This is a paragraph</p>
</body>
</html>
borderRightStyle
Object.style.borderRightStyle=style
none
hidden
"none" hidden
dotted
dashed
solid
double
border-width
groove
3D border-color
ridge
3D border-color
inset
3D inset border-color
outset
3D outset border-color
<html>
<head>
<style type="text/css">
p
{
border: thick solid #FF0000;
}
</style>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("p1").style.borderRightStyle="dotted";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorder()"
value="Change right border" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
borderRightStyle -
<html>
<head>
<style type="text/css">
p
{
border: thick solid #FF0000;
}
</style>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("p1").style.borderRightStyle="dotted";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorder()" value="Change right
border" />
<p id="p1">This is a paragraph</p>
</body>
</html>
borderRightWidth
Object.style.borderRightWidth=thin|medium|thick|length
Possible Values
thin
medium
thick
length
<html>
<head>
<style type="text/css">
p
{
border: thin solid #FF0000
}
</style>
<script type="text/javascript">
function changeBorderWidth()
{
document.getElementById("p1").style.borderRightWidth="thick";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorderWidth()"
value="Change right border width" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
borderRightWidth -
<html>
<head>
<style type="text/css">
p
{
border: thin solid #FF0000
}
</style>
<script type="text/javascript">
function changeBorderWidth()
{
document.getElementById("p1").style.borderRightWidth="thick";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorderWidth()" value="Change
right border width" />
<p id="p1">This is a paragraph</p>
</body>
</html>
borderStyle
1 4
Object.style.borderStyle=style
none
hidden
"none" hidden
dotted
dashed
solid
double
border-width
groove
3D border-color
ridge
3D border-color
inset
3D inset border-color
outset
3D outset border-color
<html>
<head>
<style>
p
{
border: thick solid #FF0000
}
</style>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("p1").style.borderStyle="dotted double";
}
</script>
</head>
<body>
<form>
<input type="button" onclick="changeBorder()"
value="Change paragraph border style" />
</form>
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
<html>
<head>
<style>
p
{
border: thick solid #FF0000
}
</style>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("p1").style.borderStyle="dotted double";
}
</script>
</head>
<body>
<form>
<input type="button" onclick="changeBorder()" value="Change
paragraph border style" />
</form>
<p id="p1">This is a paragraph</p>
</body>
</html>
borderTop
Object.style.borderTop=borderWidth borderStyle borderColor
borderWidth
borderStyle
borderColor
<html>
<head>
<style type="text/css">
p
{
border: thin dotted #FF0000
}
</style>
<script type="text/javascript">
function changeBorder()
thin
medium
thick
length
none
hidden
dotted
dashed
solid
double
groove
ridge
inset
outset
color-name
color-rgb
color-hex
transparent
{
document.getElementById("p1").style.borderTop="thick solid
#0000FF";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorder()"
value="Change top border" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
borderTop -
<html>
<head>
<style type="text/css">
p
{
border: thin dotted #FF0000
}
</style>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("p1").style.borderTop="thick solid
#0000FF";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorder()" value="Change top
border" />
<p id="p1">This is a paragraph</p>
</body>
</html>
borderTopColor
Object.style.borderTopColor=color-name|color-RGB|color-hex
<html>
<head>
<style type="text/css">
p
{
border: thick solid #FF0000
}
</style>
<script type="text/javascript">
function changeBorderColor()
{
document.getElementById("p1").style.borderTopColor="#0000FF";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorderColor()"
value="Change paragraph border color" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
borderTopColor -
<html>
<head>
<style type="text/css">
p
{
border: thick solid #FF0000
}
</style>
<script type="text/javascript">
function changeBorderColor()
{
document.getElementById("p1").style.borderTopColor="#0000FF";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorderColor()" value="Change top
border color" />
<p id="p1">This is a paragraph</p>
</body>
</html>
borderTopStyle
Object.style.borderTopStyle=style
none
hidden
"none" hidden
dotted
dashed
solid
double
border-width
groove
3D border-color
ridge
3D border-color
inset
3D inset border-color
outset
3D outset border-color
<html>
<head>
<style type="text/css">
p
{
border: thick solid #FF0000
}
</style>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("p1").style.borderTopStyle="dotted";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorder()"
value="Change border style" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
borderTopStyle -
<html>
<head>
<style type="text/css">
p
{
border: thick solid #FF0000
}
</style>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("p1").style.borderTopStyle="dotted";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorder()" value="Change top
border style" />
<p id="p1">This is a paragraph</p>
</body>
</html>
borderTopWidth
Object.style.borderTopWidth=thin|medium|thick|length
thin
medium
thick
length
<html>
<head>
<style type="text/css">
p
{
border: thin solid #FF0000
}
</style>
<script type="text/javascript">
function changeBorderWidth()
{
document.getElementById("p1").style.borderTopWidth="thick";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorderWidth()"
value="Change border width" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
borderTopWidth -
<html>
<head>
<style type="text/css">
p
{
border: thin solid #FF0000
}
</style>
<script type="text/javascript">
function changeBorderWidth()
{
document.getElementById("p1").style.borderTopWidth="thick";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorderWidth()" value="Change top
border width" />
<p id="p1">This is a paragraph</p>
</body>
</html>
borderWidth
1 4
div {border-width: thick} -
div {border-width: thick thin} -
Object.style.borderWidth=thin|medium|thick|length
thin
medium
thick
length
<html>
<head>
<style type="text/css">
p
{
border: thin solid #FF0000
}
</style>
<script type="text/javascript">
function changeBorderWidth()
{
document.getElementById("p1").style.borderWidth="thick thin";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorderWidth()"
value="Change border widths" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
borderWidth -
<html>
<head>
<style type="text/css">
p
{
border: thin solid #FF0000
}
</style>
<script type="text/javascript">
function changeBorderWidth()
{
document.getElementById("p1").style.borderWidth="thick thin";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorderWidth()" value="Change
border widths" />
margin
1 4
div {margin: 50px} - 50 px
div {margin: 50px 10px} - 50px
10 px
div {margin: 50px 10px 20px}- 50 px
10 px 20 px
div {margin: 50px 10px 20px 30px} - 50 px
10 px 20 px 30 px
Object.style.margin=margin
margin
auto
<html>
<head>
<script type="text/javascript">
function changeMargin()
{
document.getElementById("p1").style.margin="100px";
}
</script>
</head>
<body>
<input type="button" onclick="changeMargin()"
value="Change margins of a paragraph" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
margin -
<html>
<head>
<script type="text/javascript">
function changeMargin()
{
document.getElementById("p1").style.margin="100px";
}
</script>
</head>
<body>
<input type="button" onclick="changeMargin()" value="Change margins
of a paragraph" />
<p id="p1">This is a paragraph</p>
</body>
</html>
marginBottom
Object.style.marginBottom=auto|length|%
auto
length
<html>
<head>
<script type="text/javascript">
function changeMargin()
{
document.getElementById("p1").style.marginBottom="32px";
}
</script>
</head>
<body>
<input type="button" onclick="changeMargin()"
value="Change the bottom margin of a paragraph" />
<p>This is a paragraph</p>
<p id="p1">This is a paragraph</p>
<p>This is a paragraph</p>
</body>
</html>
TIY
marginBottom -
<html>
<head>
<script type="text/javascript">
function changeMargin()
{
document.getElementById("p1").style.marginBottom="32px";
}
</script>
</head>
<body>
<input type="button" onclick="changeMargin()" value="Change the
bottom margin of a paragraph" />
<p>This is a paragraph</p>
<p id="p1">This is a paragraph</p>
<p>This is a paragraph</p>
</body>
</html>
marginLeft
Object.style.marginLeft=auto|length|%
auto
length
<html>
<head>
<script type="text/javascript">
function changeMargin()
{
document.getElementById("p1").style.marginLeft="32px";
}
</script>
</head>
<body>
<input type="button" onclick="changeMargin()"
value="Change the left margin of a paragraph" />
<p>This is a paragraph</p>
<p id="p1">This is a paragraph</p>
<p>This is a paragraph</p>
</body>
</html>
TIY
marginLeft -
<html>
<head>
<script type="text/javascript">
function changeMargin()
{
document.getElementById("p1").style.marginLeft="32px";
}
</script>
</head>
<body>
<input type="button" onclick="changeMargin()" value="Change the left
margin of a paragraph" />
<p>This is a paragraph</p>
<p id="p1">This is a paragraph</p>
<p>This is a paragraph</p>
</body>
</html>
marginRight
Object.style.marginRight=auto|length|%
auto
length
<html>
<head>
<style type="text/css">
p
{
text-align: right
}
</style>
<script type="text/javascript">
function changeMargin()
{
document.getElementById("p1").style.marginRight="32px";
}
</script>
</head>
<body>
<input type="button" onclick="changeMargin()"
value="Change the right margin of a paragraph" />
<p>This is a paragraph</p>
<p id="p1">This is a paragraph</p>
<p>This is a paragraph</p>
</body>
</html>
TIY
marginRight -
<html>
<head>
<style type="text/css">
p
{
text-align: right;
}
</style>
<script type="text/javascript">
function changeMargin()
{
document.getElementById("p1").style.marginRight="32px";
}
</script>
</head>
<body>
<input type="button" onclick="changeMargin()" value="Change the
right margin of a paragraph" />
<p>This is a paragraph</p>
<p id="p1">This is a paragraph</p>
<p>This is a paragraph</p>
</body>
</html>
marginTop
Object.style.marginTop=auto|length|%
auto
length
<html>
<head>
<script type="text/javascript">
function changeMargin()
{
document.getElementById("p1").style.marginTop="32px";
}
</script>
</head>
<body>
<input type="button" onclick="changeMargin()"
value="Change the top margin of a paragraph" />
<p>This is a paragraph</p>
<p id="p1">This is a paragraph</p>
<p>This is a paragraph</p>
</body>
</html>
TIY
marginTop -
<html>
<head>
<script type="text/javascript">
function changeMargin()
{
document.getElementById("p1").style.marginTop="32px";
}
</script>
</head>
<body>
<input type="button" onclick="changeMargin()" value="Change the top
margin of a paragraph" />
<p>This is a paragraph</p>
<p id="p1">This is a paragraph</p>
<p>This is a paragraph</p>
</body>
</html>
outline
outlineWidth
outlineStyle
outlineColor
thin
medium
thick
length
none
hidden
dotted
dashed
solid
double
groove
ridge
inset
outset
color-name
color-rgb
color-hex
transparent
<html>
<head>
<style type="text/css">
p
{
border: thin solid #00FF00;
outline: thick solid #FF0000;
}
</style>
<script type="text/javascript">
function changeOutline()
{
document.getElementById("p1").style.outline="thin dotted #0000FF";
}
</script>
</head>
<body>
<input type="button" onclick="changeOutline()"
value="Change outline" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
outline - IE
<html>
<head>
<style type="text/css">
p
{
border: thin solid #00FF00;
outline: thick solid #FF0000;
}
</style>
<script type="text/javascript">
function changeOutline()
{
document.getElementById("p1").style.outline="thin dotted #0000FF";
}
</script>
</head>
<body>
<input type="button" onclick="changeOutline()" value="Change
outline" />
<p id="p1">This is a paragraph</p>
</body>
</html>
outlineColor
Object.style.outlineColor=color-name|color-rgb|color-hex
<html>
<head>
<style type="text/css">
p
{
border: thin solid #00FF00;
outline: thick solid #FF0000;
}
</style>
<script type="text/javascript">
function changeOutlineColor()
{
document.getElementById("p1").style.outlineColor="#00FF00";
}
</script>
</head>
<body>
<input type="button" onclick="changeOutlineColor()"
value="Change outline color" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
outlineColor - IE
<html>
<head>
<style type="text/css">
p
{
border: thin solid #00FF00;
outline: thick solid #FF0000;
}
</style>
<script type="text/javascript">
function changeOutlineColor()
{
document.getElementById("p1").style.outlineColor="#00FF00";
}
</script>
</head>
<body>
<input type="button" onclick="changeOutlineColor()" value="Change
outline color" />
outlineStyle
Object.style.outlineStyle=style
none
dotted
dashed
solid
double
outline-width
groove
3D outline-color
ridge
3D outline-color
inset
3D outline-color
outset
3D outline-color
<html>
<head>
<style type="text/css">
p
{
border: thin solid #00FF00;
outline: thick solid #FF0000;
}
</style>
<script type="text/javascript">
function changeOutline()
{
document.getElementById("p1").style.outlineStyle="dotted";
}
</script>
</head>
<body>
<input type="button" onclick="changeOutline()"
value="Change outline style" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
outlineStyle - IE
<html>
<head>
<style type="text/css">
p
{
border: thin solid #00FF00;
outline: thick solid #FF0000;
}
</style>
<script type="text/javascript">
function changeOutline()
{
document.getElementById("p1").style.outlineStyle="dotted";
}
</script>
</head>
<body>
<input type="button" onclick="changeOutline()" value="Change outline
style" />
<p id="p1">This is a paragraph</p>
</body>
</html>
outlineWidth
Object.style.outlineWidth=thin|medium|thick|length
thin
medium
thick
length
<html>
<head>
<style type="text/css">
p
{
border: thin solid #00FF00;
outline: thick solid #FF0000;
}
</style>
<script type="text/javascript">
function changeOutlineWidth()
{
document.getElementById("p1").style.outlineWidth="thin";
}
</script>
</head>
<body>
<input type="button" onclick="changeOutlineWidth()"
value="Change outline width" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
outlineWidth - IE
<html>
<head>
<style type="text/css">
p
{
border: thin solid #00FF00;
outline: thick solid #FF0000;
}
</style>
<script type="text/javascript">
function changeOutlineWidth()
{
document.getElementById("p1").style.outlineWidth="thin";
}
</script>
</head>
<body>
<input type="button" onclick="changeOutlineWidth()" value="Change
outline width" />
<p id="p1">This is a paragraph</p>
</body>
</html>
padding
padding
4
div {padding: 50px} - padding 50 px
div {padding: 50px 10px} - 50 px
10 px
div {padding: 50px 10px 20px} - 50 px
10 px 20 px
div {padding: 50px 10px 20px 30px} - 50 px
10 px 20 px 30 px
Object.style.padding=padding
Possible Values
padding
auto
<html>
<head>
<style type="text/css">
p
{
border: thin dotted #FF0000;
}
</style>
<script type="text/javascript">
function changePadding()
{
document.getElementById("p1").style.padding="2cm";
}
</script>
</head>
<body>
<input type="button" onclick="changePadding()"
value="Change padding" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
padding -
<html>
<head>
<style type="text/css">
p
{
border: thin dotted #FF0000;
}
</style>
<script type="text/javascript">
function changePadding()
{
document.getElementById("p1").style.padding="2cm";
}
</script>
</head>
<body>
<input type="button" onclick="changePadding()" value="Change
padding" />
<p id="p1">This is a paragraph</p>
</body>
</html>
paddingBottom
padding
Object.style.paddingBottom=length|%
length
<html>
<head>
<style type="text/css">
p
{
border: thin dotted #FF0000;
}
</style>
<script type="text/javascript">
function changePadding()
{
document.getElementById("p1").style.paddingBottom="2cm";
}
</script>
</head>
<body>
<input type="button" onclick="changePadding()"
value="Change bottom padding" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
paddingBottom -
<html>
<head>
<style type="text/css">
p
{
border: thin dotted #FF0000;
}
</style>
<script type="text/javascript">
function changePadding()
{
document.getElementById("p1").style.paddingBottom="2cm";
}
</script>
</head>
<body>
<input type="button" onclick="changePadding()" value="Change bottom
padding" />
<p id="p1">This is a paragraph</p>
</body>
</html>
paddingLeft
padding
Object.style.paddingLeft=length|%
length
<html>
<head>
<style type="text/css">
p
{
border: thin dotted #FF0000;
}
</style>
<script type="text/javascript">
function changePadding()
{
document.getElementById("p1").style.paddingLeft="2cm";
}
</script>
</head>
<body>
<input type="button" onclick="changePadding()"
value="Change left padding" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
paddingLeft -
<html>
<head>
<style type="text/css">
p
{
border: thin dotted #FF0000;
}
</style>
<script type="text/javascript">
function changePadding()
{
document.getElementById("p1").style.paddingLeft="2cm";
}
</script>
</head>
<body>
<input type="button" onclick="changePadding()" value="Change left
padding" />
<p id="p1">This is a paragraph</p>
</body>
</html>
paddingRight
padding
Object.style.paddingRight=auto|length|%
length
<html>
<head>
<style type="text/css">
p
{
border: thin dotted #FF0000;
}
</style>
<script type="text/javascript">
function changePadding()
{
document.getElementById("p1").style.paddingRight="2cm";
}
</script>
</head>
<body>
<input type="button" onclick="changePadding()"
value="Change right padding" />
<p id="p1">This is a paragraph. This is a paragraph.
This is a paragraph. This is a paragraph.
This is a paragraph. This is a paragraph.</p>
</body>
</html>
TIY
paddingRight -
<html>
<head>
<style type="text/css">
p
{
border: thin dotted #FF0000;
}
</style>
<script type="text/javascript">
function changePadding()
{
document.getElementById("p1").style.paddingRight="2cm";
}
</script>
</head>
<body>
<input type="button" onclick="changePadding()" value="Change right
padding" />
padding
padding
Object.style.paddingTop=length|%
length
<html>
<head>
<style type="text/css">
p
{
border: thin dotted #FF0000;
}
</style>
<script type="text/javascript">
function changePadding()
{
document.getElementById("p1").style.paddingTop="2cm";
}
</script>
</head>
<body>
<input type="button" onclick="changePadding()"
value="Change top padding" />
<p id="p1">This is a paragraph</p>
</body>
</html>
TIY
paddingTop -
<html>
<head>
<style type="text/css">
p
{
border: thin dotted #FF0000;
}
</style>
<script type="text/javascript">
function changePadding()
{
document.getElementById("p1").style.paddingTop="2cm";
}
</script>
</head>
<body>
<input type="button" onclick="changePadding()" value="Change top
padding" />
<p id="p1">This is a paragraph</p>
</body>
</html>
clear
Object.style.clear=left|right|both|none
left
right
both
none
<html>
<head>
<style type="text/css">
img
{
float:left;
}
</style>
<script type="text/javascript">
function clearLeft()
{
document.getElementById("p1").style.clear="left";
}
</script>
</head>
<body>
<img src="logocss.gif" width="95" height="84" />
<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
<input type="button" onclick="clearLeft()"
value="Clear left side of text" />
</body>
</html>
TIY
<html>
<head>
<style type="text/css">
img
{
float:left;
}
</style>
<script type="text/javascript">
function clearLeft()
{
document.getElementById("p1").style.clear="left";
}
</script>
</head>
<body>
<img src="/i/ct_beatles.jpg" />
<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
clip
"clip"
Object.style.clip=rect(top,right,bottom,left)|auto
rect(top,right,bottom,left)
auto
"overflow" "visible"
<html>
<head>
<style type="text/css">
img
{
position:absolute;
top:100px;
}
</style>
<script type="text/javascript">
function clipImage()
{
document.getElementById("img1").style.clip="rect(0px,50px,50px,0p
x)";
}
</script>
</head>
<body>
<img id="img1" border="0" src="logocss.gif" width="95" height="84"
/>
<input type="button" onclick=clipImage() value="Clip image" />
</body>
</html>
TIY
<html>
<head>
<style type="text/css">
img
{
position:absolute;
top:100px;
}
</style>
<script type="text/javascript">
function clipImage()
{
document.getElementById("img1").style.clip="rect(0px,50px,50px,0p
x)";
}
</script>
</head>
<body>
<img id="img1" border="0" src="/i/eg_sun.gif" />
<input type="button" onclick=clipImage() value="Clip image" />
</body>
</html>
content
Object.style.content=value
string
url
url
counter(name)
counter(name, list-style-type)
counters(name, string)
counters(name,
string,
list-style-type)
attr(X)
open-quote
close-quote
no-open-quote
no-close-quote
<html>
<head>
<script type="text/javascript">
function setFloatLeft()
{
document.getElementById("img1").style.cssFloat="left";
}
</script>
</head>
<body>
<img id="img1" src="logocss.gif" width="95" height="84" />
<p>This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
<form>
<input type="button" onclick="setFloatLeft()" value="Set image to
float left" />
</form>
</body>
</html>
TIY
<html>
<head>
<script type="text/javascript">
function setFloat()
{
document.getElementById("img1").style.cssFloat="left";
}
</script>
</head>
<body>
<img id="img1" src="/i/ct_beatles.jpg" />
<p>This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
<input type="button" onclick="setFloat()" value="Set image to float
to the left" />
</body>
</html>
Object.style.cssFloat=left|right|none
left
right
none
<html>
<head>
<script type="text/javascript">
function setFloat()
{
document.getElementById("img1").style.cssFloat="left";
}
</script>
</head>
<body>
<img id="img1" src="logocss.gif" />
<p>This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
<input type="button" onclick="setFloat()"
value="Set image to float to the left" />
</body>
</html>
TIY
cssFloat - IE
<html>
<head>
<script type="text/javascript">
function setFloat()
{
document.getElementById("img1").style.cssFloat="left";
}
</script>
</head>
<body>
<img id="img1" src="/i/ct_beatles.jpg" />
<p>This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
<input type="button" onclick="setFloat()" value="Set image to float
to the left" />
</body>
</html>
cursor
Object.style.cursor=cursortype
url
URL
URL
default
auto
crosshair
pointer
move
e-resize
ne-resize
nw-resize
n-resize
se-resize
sw-resize
s-resize
w-resize
text
wait
help
<html>
<head>
<script type="text/javascript">
function changeCursor()
{
document.body.style.cursor="crosshair";
document.getElementById("p1").style.cursor="text";
}
</script>
</head>
<body>
<p id="p1">This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text.</p>
<input type="button" onclick="changeCursor()"
value="Change cursor" />
</body>
</html>
TIY
cursor -
<html>
<head>
<script type="text/javascript">
function changeCursor()
{
document.body.style.cursor="crosshair";
document.getElementById("p1").style.cursor="text";
}
</script>
</head>
<body>
<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
<input type="button" onclick="changeCursor()" value="Change cursor"
/>
</body>
</html>
direction
Object.style.direction=ltr|rtl|inherit
Possible Values
ltr
rtl
inherit
<html>
<head>
<script type="text/javascript">
function changeTextDirection()
{
document.getElementById("p1").style.direction="rtl";
}
</script>
</head>
<body>
<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
<input type="button" onclick="changeTextDirection()"
TIY
direction -
<html>
<head>
<script type="text/javascript">
function changeTextDirection()
{
document.getElementById("p1").style.direction="rtl";
}
</script>
</head>
<body>
<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
<input type="button" onclick="changeTextDirection()" value="Set text
to flow from right to left" />
</body>
</html>
display
Object.style.display=value
Possible Values
none
block
inline
list-item
run-in
compact
marker
table
<table>
inline-table
<table>
table-row-group
<tbody>
table-header-group
<thead>
table-footer-group
<tfoot>
table-row
<tr>
table-column-group
<colgroup>
table-column
<col>
table-cell
<td> <th>
table-caption
<caption>
<html>
<head>
<script type="text/javascript">
function removeElement()
{
document.getElementById("p1").style.display="none";
}
</script>
</head>
<body>
<h1>Hello</h1>
<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
<input type="button" onclick="removeElement()"
value="Do not display paragraph" />
</body>
</html>
TIY
display -
<html>
<head>
<script type="text/javascript">
function removeElement()
{
document.getElementById("p1").style.display="none";
}
</script>
</head>
<body>
<h1>This is a header</h1>
<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
<input type="button" onclick="removeElement()" value="Do not display
paragraph" />
</body>
</html>
height
Object.style.height=auto|length|%
auto
length
pxcm
<html>
<head>
<script type="text/javascript">
function setHeight()
{
document.getElementById("b1").style.height="50px";
}
</script>
</head>
<body>
<input type="button" id="b1" onclick="setHeight()"
value="Change height of button to 50 px" />
</body>
</html>
TIY
height -
<html>
<head>
<script type="text/javascript">
function setHeight()
{
document.getElementById("b1").style.height="50px";
}
</script>
</head>
<body>
<input type="button" id="b1" onclick="setHeight()" value="Change
height of button to 50 px" />
</body>
</html>
maxHeight
Object.style.maxHeight=length|%
length
<html>
<head>
<script type="text/javascript">
function setMaxHeight()
{
document.getElementById("p1").style.maxHeight="10px";
}
</script>
</head>
<body>
<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
<input type="button" onclick="setMaxHeight()"
value="Set max height" />
</body>
</html>
TIY
maxHeight -
<html>
<head>
<script type="text/javascript">
function setMaxHeight()
{
document.getElementById("p1").style.maxHeight="10px";
}
</script>
</head>
<body>
<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
maxWidth
Object.style.maxWidth=length|%
length
<html>
<head>
<script type="text/javascript">
function setMaxWidth()
{
document.getElementById("p1").style.maxWidth="10px";
}
</script>
</head>
<body>
<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
<input type="button" onclick="setMaxWidth()"
value="Set max width" />
</body>
</html>
TIY
maxWidth -
<html>
<head>
<script type="text/javascript">
function setMaxWidth()
{
document.getElementById("p1").style.maxWidth="10px";
}
</script>
</head>
<body>
<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
<input type="button" onclick="setMaxWidth()" value="Set max width"
/>
</body>
</html>
minHeight
Object.style.minHeight=length|%
length
<html>
<head>
<script type="text/javascript">
function setMinHeight()
{
document.getElementById("p1").style.minHeight="200px";
}
</script>
</head>
<body>
<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
<input type="button" onclick="setMinHeight()"
value="Set min height" />
</body>
</html>
TIY
minHeight -
<html>
<head>
<script type="text/javascript">
function setMinHeight()
{
document.getElementById("p1").style.minHeight="200px";
}
</script>
</head>
<body>
<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
<input type="button" onclick="setMinHeight()" value="Set min height"
/>
</body>
</html>
minWidth
Object.style.minWidth=length|%
length
<html>
<head>
<script type="text/javascript">
function setMinWidth()
{
document.getElementById("p1").style.minWidth="1000px";
}
</script>
</head>
<body>
<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
<input type="button" onclick="setMinWidth()" value="Set min width"
/>
</body>
</html>
TIY
minWidth -
<html>
<head>
<script type="text/javascript">
function setMinWidth()
{
document.getElementById("p1").style.minWidth="1000px";
}
</script>
</head>
<body>
<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
<input type="button" onclick="setMinWidth()" value="Set min width"
/>
</body>
</html>
overflow
Object.style.overflow=visible|hidden|scroll|auto
visible
hidden
scroll
auto
overflow
<html>
<head>
<style type="text/css">
div
{
border:thin solid green;
width:100px;
height:100px;
}
</style>
<script type="text/javascript">
function hideOverflow()
{
document.getElementById("div1").style.overflow="hidden";
}
</script>
</head>
<body>
<div id="div1">
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</div>
<br />
<input type="button" onclick="hideOverflow()"
value="Hide overflow" />
</body>
</html>
TIY
overflow -
<html>
<head>
<style type="text/css">
div
{
border:thin solid green;
width:100px;
height:100px;
}
</style>
<script type="text/javascript">
function hideOverflow()
{
document.getElementById("div1").style.overflow="hidden";
}
</script>
</head>
<body>
<div id="div1">
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</div>
<br />
<input type="button" onclick="hideOverflow()" value="Hide overflow"
/>
</body>
</html>
verticalAlign
Object.style.verticalAlign=value
baseline
sub
super
top
text-top
middle
bottom
text-bottom
length
%
"line-height"
<html>
<head>
<script type="text/javascript">
function alignText()
{
document.getElementById("td1").style.verticalAlign="bottom";
}
</script>
</head>
<body>
<table border="1" height="100px">
<tr>
<td id="td1">
Some example text
</td>
</tr>
</table>
<br />
TIY
verticalAlign -
<html>
<head>
<script type="text/javascript">
function alignText()
{
document.getElementById("td1").style.verticalAlign="bottom";
}
</script>
</head>
<body>
<table border="1" height="100px">
<tr>
<td id="td1">
Some example text
</td>
</tr>
</table>
<br />
<input type="button" onclick="alignText()" value="Align text" />
</body>
</html>
visibility
Object.style.visibility=visible|hidden|collapse
visible
hidden
collapse
"hidden"
<html>
<head>
<script type="text/javascript">
function changeVisibility()
{
document.getElementById("p1").style.visibility="hidden";
}
</script>
</head>
<body>
<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
<form>
<input type="button" onclick="changeVisibility()"
value="Hide paragraph" />
</form>
</body>
</html>
TIY
visibility -
<html>
<head>
<script type="text/javascript">
function changeVisibility()
{
document.getElementById("p1").style.visibility="hidden";
}
</script>
</head>
<body>
<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>
<input type="button" onclick="changeVisibility()" value="Hide text"
/>
</body>
</html>
width
Object.style.width=auto|length|%
auto
length
pxcm
<html>
<head>
<script type="text/javascript">
function setWidth()
{
document.getElementById("b1").style.width="300px";
}
</script>
</head>
<body>
<input type="button" id="b1" onclick="setWidth()"
value="Change width to 300 px" />
</body>
</html>
TIY
width -
<html>
<head>
<script type="text/javascript">
function setWidth()
{
document.getElementById("b1").style.width="300px";
}
</script>
</head>
<body>
<input type="button" id="b1" onclick="setWidth()" value="Change
listStyle
Object.style.listStyle=listStyleType listStylePosition
listStyleImage
Possible Values
listStyleType
none
disc
circle
square
decimal
decimal-leading-zero
lower-roman
upper-roman
lower-alpha
upper-alpha
lower-greek
lower-latin
upper-latin
hebrew
armenian
georgian
cjk-ideographic
hiragana
katakana
listStylePosition
listStyleImage
hiragana-iroha
katakana-iroha
outside
inside
none
url(url)
<html>
<head>
<script type="text/javascript">
function changeList()
{
document.getElementById("ul1").style.listStyle="decimal inside";
}
</script>
</head>
<body>
<ul id="ul1">
<li>Coffee</li>
<li>Tea</li>
<li>Water</li>
<li>Soda</li>
</ul>
<input type="button" onclick="changeList()"
value="Change list style" />
</body>
</html>
TIY
listStyle -
<html>
<head>
<script type="text/javascript">
function changeList()
{
document.getElementById("ul1").style.listStyle="decimal inside";
}
</script>
</head>
<body>
<ul id="ul1">
<li>Coffee</li>
<li>Tea</li>
<li>Water</li>
<li>Soda</li>
</ul>
<input type="button" onclick="changeList()" value="Change list
style" />
</body>
</html>
listStyleImage
Object.style.listStyleImage=url|none
url
none
<html>
<head>
<script type="text/javascript">
function changeList()
{
document.getElementById("ul1").style.listStyleImage="url('blueb.g
if')";
}
</script>
</head>
<body>
<ul id="ul1">
<li>Coffee</li>
<li>Tea</li>
<li>Water</li>
<li>Soda</li>
</ul>
<input type="button" onclick="changeList()"
value="Change list-item marker" />
</body>
</html>
TIY
listStyleImage -
<html>
<head>
<script type="text/javascript">
function changeList()
{
document.getElementById("ul1").style.listStyleImage="url('/i/ct_b
lueball.gif')";
}
</script>
</head>
<body>
<ul id="ul1">
<li>Coffee</li>
<li>Tea</li>
<li>Water</li>
<li>Soda</li>
</ul>
<input type="button" onclick="changeList()" value="Change list-item
marker" />
</body>
</html>
listStylePosition
Object.style.listStylePosition=inside|outside
inside
outside
<html>
<head>
<script type="text/javascript">
function changeList()
{
document.getElementById("ul1").style.listStylePosition="inside";
}
</script>
</head>
<body>
<ul id="ul1">
<li>Coffee</li>
<li>Tea</li>
<li>Water</li>
<li>Soda</li>
</ul>
<input type="button" onclick="changeList()"
value="Change list-item marker position" />
</body>
</html>
TIY
listStylePosition -
<html>
<head>
<script type="text/javascript">
function changeList()
{
document.getElementById("ul1").style.listStylePosition="inside";
}
</script>
</head>
<body>
<ul id="ul1">
<li>Coffee</li>
<li>Tea</li>
<li>Water</li>
<li>Soda</li>
</ul>
<input type="button" onclick="changeList()" value="Change list-item
marker position" />
</body>
</html>
listStyleType
Object.style.listStyleType=value
CSS2
none
disc
circle
square
decimal
decimal-leading-zero
lower-roman
upper-roman
lower-alpha
upper-alpha
lower-greek
lower-latin
(a, b, c, d, e, )
upper-latin
(A, B, C, D, E, )
hebrew
armenian
georgian
cjk-ideographic
hiragana
a, i, u, e, o, ka, ki,
katakana
A, I, U, E, O, KA, KI,
hiragana-iroha
katakana-iroha
CSS2.1
disc | circle | square | decimal | decimal-leading-zero |
lower-roman | upper-roman | lower-greek | lower-latin | upper-latin
| armenian | georgian | none | inherit
<html>
<head>
<script type="text/javascript">
function changeList()
{
document.getElementById("ul1").style.listStyleType="square";
}
</script>
</head>
<body>
<ul id="ul1">
<li>Coffee</li>
<li>Tea</li>
<li>Water</li>
<li>Soda</li>
</ul>
<input type="button" onclick="changeList()"
value="Change list-item marker type" />
</body>
</html>
TIY
listStyleType -
<html>
<head>
<script type="text/javascript">
function changeList()
{
document.getElementById("ul1").style.listStyleType="square";
}
</script>
</head>
<body>
<ul id="ul1">
<li>Coffee</li>
<li>Tea</li>
<li>Water</li>
<li>Soda</li>
</ul>
<input type="button" onclick="changeList()" value="Change list-item
marker type" />
</body>
</html>
bottom
Object.style.bottom=auto|%|length
auto
length
pxcm
<html>
<head>
<style type="text/css">
input
{
position:absolute;
}
</style>
<script type="text/javascript">
function setBottomEdge()
{
document.getElementById("b1").style.bottom="100px";
}
</script>
</head>
<body>
<input type="button" id="b1" onclick="setBottomEdge()"
value="Set bottom edge to 100 px" />
</body>
</html>
TIY
bottom -
<html>
<head>
<style type="text/css">
input
{
position:absolute;
}
</style>
<script type="text/javascript">
function setBottomEdge()
{
document.getElementById("b1").style.bottom="100px";
}
</script>
</head>
<body>
<input type="button" id="b1" onclick="setBottomEdge()" value="Set
bottom edge to 100 px" />
</body>
</html>
left
Object.style.left=auto|%|length
auto
length
pxcm
<html>
<head>
<style type="text/css">
input
{
position:absolute;
}
</style>
<script type="text/javascript">
function setLeftEdge()
{
document.getElementById("b1").style.left="100px";
}
</script>
</head>
<body>
<input type="button" id="b1" onclick="setLeftEdge()"
value="Set left edge to 100 px" />
</body>
</html>
TIY
left -
<html>
<head>
<style type="text/css">
input
{
position:absolute;
}
</style>
<script type="text/javascript">
function setLeftEdge()
{
document.getElementById("b1").style.left="100px";
}
</script>
</head>
<body>
<input type="button" id="b1" onclick="setLeftEdge()" value="Set left
edge to 100 px" />
</body>
</html>
position
Object.style.position=static|relative|absolute|fixed
static
static static
topbottomleft right
relative
relative
"left:20" 20
absolute
absolute
"left""top""right" "bottom"
fixed
fixed
"left""top""right" "bottom"
IE7strict
<html>
<head>
<style type="text/css">
input
{
position:relative;
}
</style>
<script type="text/javascript">
function setPositionAbsolute()
{
document.getElementById("b1").style.position="absolute";
document.getElementById("b1").style.top="10px";
}
</script>
</head>
<body>
<p>This is an example paragraph</p>
<p>This is an example paragraph</p>
<input type="button" id="b1" onclick="setPositionAbsolute()"
value="Set button position to be absolute" />
</body>
</html>
TIY
position -
<html>
<head>
<style type="text/css">
input
{
position:relative;
}
</style>
<script type="text/javascript">
function setPositionAbsolute()
{
document.getElementById("b1").style.position="absolute";
document.getElementById("b1").style.top="10px";
}
</script>
</head>
<body>
<p>This is an example paragraph</p>
<p>This is an example paragraph</p>
<p>This is an example paragraph</p>
<p>This
<p>This
<p>This
<p>This
<p>This
<p>This
<p>This
<p>This
<p>This
<p>This
<p>This
is
is
is
is
is
is
is
is
is
is
is
an
an
an
an
an
an
an
an
an
an
an
example
example
example
example
example
example
example
example
example
example
example
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
right
Object.style.right=auto|%|length
auto
length
pxcm
"position" "static" "right"
<html>
<head>
<style type="text/css">
input
{
position:absolute;
}
</style>
<script type="text/javascript">
function setRightEdge()
{
document.getElementById("b1").style.right="100px";
}
</script>
</head>
<body>
<input type="button" id="b1" onclick="setRightEdge()"
value="Set right edge to 100 px" />
</body>
</html>
TIY
right -
<html>
<head>
<style type="text/css">
input
{
position:absolute;
}
</style>
<script type="text/javascript">
function setRightEdge()
{
document.getElementById("b1").style.right="100px";
}
</script>
</head>
<body>
<input type="button" id="b1" onclick="setRightEdge()" value="Set
right edge to 100 px" />
</body>
</html>
top
Object.style.top=auto|%|length
auto
length
pxcm
<html>
<head>
<style type="text/css">
input
{
position:absolute;
}
</style>
<script type="text/javascript">
function setTopEdge()
{
document.getElementById("b1").style.top="100px";
}
</script>
</head>
<body>
<input type="button" id="b1" onclick="setTopEdge()"
value="Set top edge to 100 px" />
</body>
</html>
TIY
top -
<html>
<head>
<style type="text/css">
input
{
position:absolute;
}
</style>
<script type="text/javascript">
function setTopEdge()
{
document.getElementById("b1").style.top="100px";
}
</script>
</head>
<body>
<input type="button" id="b1" onclick="setTopEdge()" value="Set top
edge to 100 px" />
</body>
</html>
zIndex
z z
Object.style.zIndex=auto|number
auto
number
z-index
Z-index position:absolute;
<html>
<head>
<style type="text/css">
#img1
{
position:absolute;
left:0px;
top:0px;
z-index:-1
}
</style>
<script type="text/javascript">
function changeStackOrder()
{
document.getElementById("img1").style.zIndex="1";
}
</script>
</head>
<body>
<h1>This is a Heading</h1>
<img id="img1" src="bulbon.gif" width="100" height="180">
<p>Default z-index is 0. Z-index -1 has lower priority.</p>
<input type="button" onclick="changeStackOrder()"
value="Change stack order" />
</body>
</html>
TIY
zIndex -
<html>
<head>
<style type="text/css">
#img1
{
position:absolute;
left:0px;
top:0px;
z-index:-1
}
</style>
<script type="text/javascript">
function changeStackOrder()
{
document.getElementById("img1").style.zIndex="1";
}
</script>
</head>
<body>
<h1>This is a Heading</h1>
<img id="img1" src="/i/eg_bulbon.gif">
<p>Default z-index is 0. Z-index -1 has lower priority.</p>
<input type="button" onclick="changeStackOrder()" value="Change
stack order" />
</body>
</html>
pageBreakAfter
Object.style.pageBreakAfter=auto|always|avoid|left|right
auto
always
avoid
left
right
id p1 page-break
<html>
<head>
<script type="text/javascript">
function setPageBreak()
{
document.getElementById("p1").style.pageBreakAfter="always";
}
</script>
</head>
<body>
<p id="p1">This is a test paragraph.</p>
<input type="button" onclick="setPageBreak()"
value="Set page-break" />
<p>This is also a test paragraph.</p>
</body>
</html>
pageBreakBefore
Object.style.pageBreakBefore=auto|always|avoid|left|right
auto
always
avoid
left
right
id p2 page-break
<html>
<head>
<script type="text/javascript">
function setPageBreak()
{
document.getElementById("p2").style.pageBreakBefore="always";
}
</script>
</head>
<body>
<p>This is a test paragraph.</p>
pageBreakInside
Object.style.pageBreakInside=auto|avoid
auto
avoid
id p2 page-break
<html>
<head>
<script type="text/javascript">
function setPageBreak()
{
document.getElementById("p2").style.pageBreakInside="avoid";
}
</script>
</head>
<body>
<p>This is a test paragraph.</p>
<input type="button" onclick="setPageBreak()"
value="Set page to not break inside the second paragraph" />
<p id="p2">This is also a test paragraph. We need some
more text here. This is just filler text.</p>
</body>
</html>
scrollbar3dLightColor
Object.style.scrollbar3dLightColor=color
color
<html>
<head>
<script type="text/javascript">
function setScrollbar3dLightColor()
{
document.body.style.scrollbar3dLightColor="blue";
}
</script>
</head>
<body>
<input type="button" onclick="setScrollbar3dLightColor()"
value="Set Scrollbar3dLightColor" />
</body>
</html>
TIY
scrollbar3dLightColor
<html>
<head>
<script type="text/javascript">
function setScrollbar3dLightColor()
{
document.body.style.scrollbar3dLightColor="blue";
}
</script>
</head>
<body>
<input type="button" onclick="setScrollbar3dLightColor()"
value="Set Scrollbar3dLightColor" />
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
example
example
example
example
example
example
example
example
example
example
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
scrollbarArrowColor
Object.style.scrollbarArrowColor=color
color
<html>
<head>
<script type="text/javascript">
function setScrollbarArrowColor()
{
document.body.style.scrollbarArrowColor="green";
}
</script>
</head>
<body>
<input type="button" onclick="setScrollbarArrowColor()"
value="Set ScrollbarArrowColor" />
</body>
</html>
TIY
scrollbarArrowColor
<html>
<head>
<script type="text/javascript">
function setScrollbarArrowColor()
{
document.body.style.scrollbarArrowColor="green";
}
</script>
</head>
<body>
<input type="button" onclick="setScrollbarArrowColor()" value="Set
ScrollbarArrowColor" />
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
example
example
example
example
example
example
example
example
example
example
example
</body>
</html>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
scrollbarBaseColor
Object.style.scrollbarBaseColor=color
color
<html>
<head>
<script type="text/javascript">
function setScrollbarColor()
{
document.body.style.scrollbarBaseColor="green";
}
</script>
</head>
<body>
<input type="button" onclick="setScrollbarColor()"
value="Set ScrollbarColor" />
</body>
</html>
TIY
scrollbarColor
<html>
<head>
<script type="text/javascript">
function setScrollbarColor()
{
document.body.style.scrollbarBaseColor="green";
}
</script>
</head>
<body>
<input type="button" onclick="setScrollbarColor()" value="Set
ScrollbarColor" />
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
example
example
example
example
example
example
example
example
example
example
example
</body>
</html>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
HTML DOM
scrollbarDarkShadowColor
scrollbarDarkShadowColor
scrollbarShadowColor
Object.style.scrollbarDarkShadowColor=color
color
<html>
<head>
<script type="text/javascript">
function setScrollbarDarkShadowColor()
{
document.body.style.scrollbarDarkShadowColor="darkred";
}
</script>
</head>
<body>
<input type="button" onclick="setScrollbarDarkShadowColor()"
value="Set ScrollbarDarkShadowColor" />
</body>
</html>
TIY
scrollbarDarkShadowColor
<html>
<head>
<script type="text/javascript">
function setScrollbarDarkShadowColor()
{
document.body.style.scrollbarDarkShadowColor="darkred";
}
</script>
</head>
<body>
<input type="button" onclick="setScrollbarDarkShadowColor()"
value="Set ScrollbarDarkShadowColor" />
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
example
example
example
example
example
example
example
example
example
example
example
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
</body>
</html>
scrollbarFaceColor
Object.style.scrollbarFaceColor=color
color
<html>
<head>
<script type="text/javascript">
function setScrollbarFaceColor()
{
document.body.style.scrollbarFaceColor="green";
}
</script>
</head>
<body>
<input type="button" onclick="setScrollbarFaceColor()"
value="Set ScrollbarFaceColor" />
</body>
</html>
TIY
scrollbarFaceColor
<html>
<head>
<script type="text/javascript">
function setScrollbarFaceColor()
{
document.body.style.scrollbarFaceColor="green";
}
</script>
</head>
<body>
<input type="button" onclick="setScrollbarFaceColor()" value="Set
ScrollbarFaceColor" />
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
example
example
example
example
example
example
example
example
example
example
example
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
</body>
</html>
scrollbarHighlightColor
Object.style.scrollbarHighlightColor=color
color
<html>
<head>
<script type="text/javascript">
function setScrollbarHighlightColor()
{
document.body.style.scrollbarHighlightColor="purple";
}
</script>
</head>
<body>
<input type="button" onclick="setScrollbarHighlightColor()"
value="Set ScrollbarHighlightColor" />
</body>
</html>
TIY
scrollbarHighlightColor
<html>
<head>
<script type="text/javascript">
function setScrollbarHighlightColor()
{
document.body.style.scrollbarHighlightColor="purple";
}
</script>
</head>
<body>
<input type="button" onclick="setScrollbarHighlightColor()"
value="Set ScrollbarHighlightColor" />
<p>An example paragraph</p>
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
example
example
example
example
example
example
example
example
example
example
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
</body>
</html>
scrollbarShadowColor
scrollbarDarkShadowColor
Object.style.scrollbarShadowColor=color
Color
<html>
<head>
<script type="text/javascript">
function setScrollbarShadowColor()
{
document.body.style.scrollbarShadowColor="pink";
}
</script>
</head>
<body>
<input type="button" onclick="setScrollbarShadowColor()"
value="Set ScrollbarShadowColor" />
</body>
</html>
TIY
scrollbarShadowColor
<html>
<head>
<script type="text/javascript">
function setScrollbarShadowColor()
{
document.body.style.scrollbarShadowColor="pink";
}
</script>
</head>
<body>
<input type="button" onclick="setScrollbarShadowColor()" value="Set
ScrollbarShadowColor" />
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
example
example
example
example
example
example
example
example
example
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
scrollbarTrackColor
Object.style.scrollbarTrackColor=color
color
<html>
<head>
<script type="text/javascript">
function setScrollbarTrackColor()
{
document.body.style.scrollbarTrackColor="pink";
}
</script>
</head>
<body>
<input type="button" onclick="setScrollbarTrackColor()"
value="Set ScrollbarTrackColor" />
</body>
</html>
TIY
scrollbarTrackColor
<html>
<head>
<script type="text/javascript">
function setScrollbarTrackColor()
{
document.body.style.scrollbarTrackColor="pink";
}
</script>
</head>
<body>
<input type="button" onclick="setScrollbarTrackColor()" value="Set
ScrollbarTrackColor" />
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
<p>An
example
example
example
example
example
example
example
example
example
example
example
</body>
</html>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
paragraph</p>
borderCollapse HTML
Object.style.borderCollapse=collapse|separate
separate
collapse
<html>
<head>
<script type="text/javascript">
function setBorderCollapse()
{
document.getElementById('myTable').style.borderCollapse="collapse
"
}
</script>
</head>
<body>
<table border="1" id="myTable">
<tr>
<td>100</td>
<td>200</td>
</tr>
<tr>
<td>300</td>
<td>400</td>
</tr>
</table>
<br />
<input type="button" onclick="setBorderCollapse()"
value="Collapse border">
</body>
</html>
TIY
borderCollapse -
<html>
<head>
<script type="text/javascript">
function setBorderCollapse()
{
document.getElementById('myTable').style.borderCollapse="collapse
";
}
</script>
</head>
<body>
<table border="1" id="myTable">
<tr>
<td>100</td>
<td>200</td>
</tr>
<tr>
<td>300</td>
<td>400</td>
</tr>
</table>
<br />
<input type="button" onclick="setBorderCollapse()" value="Collapse
border">
</body>
</html>
borderSpacing
Object.style.borderSpacing=length,length
length length
pxcm length
length
length
<html>
<head>
<script type="text/javascript">
function changeBorderSpacing()
{
document.getElementById('myTable').style.borderSpacing="10px"
}
</script>
</head>
<body>
<table border="1" id="myTable">
<tr>
<td>100</td>
<td>200</td>
</tr>
<tr>
<td>300</td>
<td>400</td>
</tr>
</table>
<input type="button" onclick="changeBorderSpacing()"
value="Change border spacing">
</body>
</html>
TIY
borderSpacing - IE
<html>
<head>
<script type="text/javascript">
function changeBorderSpacing()
{
document.getElementById('myTable').style.borderSpacing="10px";
}
</script>
</head>
<body>
<table border="1" id="myTable">
<tr>
<td>100</td>
<td>200</td>
</tr>
<tr>
<td>300</td>
<td>400</td>
</tr>
</table>
<br />
<input type="button" onclick="changeBorderSpacing()" value="Change
border spacing">
</body>
</html>
captionSide
Object.style.captionSide=top|bottom|left|right
top
bottom
left
right
<html>
<head>
<style type="text/css">
caption
{
caption-side:bottom;
}
</style>
<script type="text/javascript">
function moveCaption()
{
document.getElementById('myTable').style.captionSide="right"
}
</script>
</head>
<body>
<table border="1" id="myTable">
<caption>This is a caption</caption>
<tr>
<td>100</td>
<td>200</td>
</tr>
<tr>
<td>300</td>
<td>400</td>
</tr>
</table>
<br />
<input type="button" onclick="moveCaption()"
value="Move table caption">
</body>
</html>
TIY
captionSide - IE
<html>
<head>
<style type="text/css">
caption
{
caption-side:bottom;
}
</style>
<script type="text/javascript">
function moveCaption()
{
document.getElementById('myTable').style.captionSide="right";
}
</script>
</head>
<body>
<table border="1" id="myTable">
<caption>This is a caption</caption>
<tr>
<td>100</td>
<td>200</td>
</tr>
<tr>
<td>300</td>
<td>400</td>
</tr>
</table>
<br />
<input type="button" onclick="moveCaption()" value="Move table
caption">
</body>
</html>
emptyCells
Object.style.emptyCells=hide|show
hide
show
<html>
<head>
<script type="text/javascript">
function showEmptyCells()
{
document.getElementById('myTable').style.emptyCells="show"
}
</script>
</head>
<body>
<table border="1" id="myTable">
<tr>
<td>100</td>
<td>200</td>
</tr>
<tr>
<td>300</td>
<td></td>
</tr>
</table>
<input type="button" onclick="showEmptyCells()"
value="Show empty cells">
</body>
</html>
TIY
<html>
<head>
<script type="text/javascript">
function showEmptyCells()
{
document.getElementById('myTable').style.emptyCells="show";
}
</script>
</head>
<body>
<table border="1" id="myTable">
<tr>
<td>100</td>
<td>200</td>
</tr>
<tr>
<td>300</td>
<td></td>
</tr>
</table>
<input type="button" onclick="showEmptyCells()" value="Show empty
cells">
</body>
</html>
tableLayout
Object.style.tableLayout=automatic|fixed
automatic
fixed
<html>
<head>
<script type="text/javascript">
function setFixedTableLayout()
{
document.getElementById('myTable').style.tableLayout="fixed";
}
</script>
</head>
<body>
<table id="myTable" border="1" width="100%">
<col width="20%"><col width="40%"><col width="40%">
<tr>
<td>1000000000000000000000000000</td>
<td>10000000</td>
<td>100</td>
</tr>
</table>
<input type="button" onclick="setFixedTableLayout()"
value="Set fixed table layout">
</body>
</html>
TIY
(tableLayout)
<html>
<head>
<script type="text/javascript">
function setFixedTableLayout()
{
document.getElementById('myTable').style.tableLayout="fixed";
}
</script>
</head>
<body>
<table id="myTable" border="1" width="100%">
<col width="20%"><col width="40%"><col width="40%">
<tr>
<td>1000000000000000000000000000</td>
<td>10000000</td>
<td>100</td>
</tr>
</table>
<input type="button" onclick="setFixedTableLayout()" value="Set
fixed table layout">
</body>
</html>
color
Object.style.color=color
color
rgb
<html>
<head>
<script type="text/javascript">
function setColor()
{
document.getElementById("p1").style.color="#ff0000";
document.getElementById("p2").style.color="magenta";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph</p>
<p id="p2">This is also an example paragraph</p>
<input type="button" onclick="setColor()"
value="Change color of text" />
</body>
</html>
TIY
<html>
<head>
<script type="text/javascript">
function setColor()
{
document.getElementById("p1").style.color="#ff0000";
document.getElementById("p2").style.color="magenta";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph.</p>
<p id="p2">This is also an example paragraph.</p>
<input type="button" onclick="setColor()" value="Change color of
text" />
</body>
</html>
font
Object.style.font=value
fontStyle
fontVariant
fontWeight
fontSize/lineHeight
fontFamily
caption
icon
menu
message-box
small-caption
status-bar
<html>
<head>
<script type="text/javascript">
function setFont()
{
document.getElementById("p1").style.font="italic bold 12px
arial,serif";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph.</p>
<input type="button" onclick="setFont()" value="Change paragraph
style" />
</body>
</html>
TIY
<html>
<head>
<script type="text/javascript">
function setFont()
{
document.getElementById("p1").style.font="italic bold 12px
arial,serif";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph.</p>
<input type="button" onclick="setFont()" value="Change font" />
</body>
</html>
fontFamily
Object.style.fontFamily=font1,font2,....
Value
Description
font1, font2,....
<html>
<head>
<script type="text/javascript">
function setFont()
{
document.getElementById("p1").style.fontFamily="arial,sans-serif"
;
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph.</p>
<input type="button" onclick="setFont()" value="Change font" />
</body>
</html>
TIY
fontFamily -
<html>
<head>
<script type="text/javascript">
function setFont()
{
document.getElementById("p1").style.fontFamily="arial,sans-serif"
;
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph.</p>
<input type="button" onclick="setFont()" value="Change font" />
</body>
</html>
fontSize
Object.style.fontSize=value
xx-small
x-small
small
medium
large
x-large
xx-large
xx-small xx-large
medium
smaller
font-size
larger
font-size
length
font-size
font-size
<html>
<head>
<script type="text/javascript">
function setFontSize()
{
document.getElementById("p1").style.fontSize="larger";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph.</p>
<input type="button" onclick="setFontSize()"
value="Change font-size" />
</body>
</html>
TIY
fontSize -
<html>
<head>
<script type="text/javascript">
function setFontSize()
{
document.getElementById("p1").style.fontSize="larger";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph.</p>
<input type="button" onclick="setFontSize()" value="Change
font-size" />
</body>
</html>
fontSizeAdjust
aspect x-height
Object.style.fontSizeAdjust=none|number
none
x-height
number
aspect
* font-size-adjust / aspect =
<html>
<head>
<script type="text/javascript">
function adjustFontSize()
{
document.getElementById("p1").style.fontSizeAdjust="0.70";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph</p>
TIY
fontSizeAdjust -
<html>
<head>
<script type="text/javascript">
function adjustFontSize()
{
document.getElementById("p1").style.fontSizeAdjust="0.70";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph</p>
<input type="button" onclick="adjustFontSize()" value="Adjust
font-size" />
</body>
</html>
fontStretch font-family
Object.style.fontStretch=value
normal
wider
narrower
ultra-condensed
extra-condensed
condensed
semi-condensed
semi-expanded
expanded
extra-expanded
ultra-expanded
font-family
"ultra-condensed" "ultra-expanded"
<html>
<head>
<script type="text/javascript">
function setFontStretch()
{
document.getElementById("p1").style.fontStretch="ultra-expanded";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph.</p>
<input type="button" onclick="setFontStretch()"
value="Stretch font" />
</body>
</html>
TIY
fontStretch -
<html>
<head>
<script type="text/javascript">
function setFontStretch()
{
document.getElementById("p1").style.fontStretch="ultra-expanded";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph.</p>
<input type="button" onclick="setFontStretch()" value="Stretch font"
/>
</body>
</html>
fontStyle
Object.style.fontStyle=normal|italic|oblique
normal
italic
oblique
<html>
<head>
<script type="text/javascript">
function setFontStyle()
{
document.getElementById("p1").style.fontStyle="italic";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph.</p>
<input type="button" onclick="setFontStyle()"
value="Change font-style" />
</body>
</html>
TIY
fontStyle -
<html>
<head>
<script type="text/javascript">
function setFontStyle()
{
document.getElementById("p1").style.fontStyle="italic";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph.</p>
fontVariant
Object.style.fontVariant=normal|small-caps
normal
small-caps
<html>
<head>
<script type="text/javascript">
function setSmallCaps()
{
document.getElementById("p1").style.fontVariant="small-caps";
}
</script>
</head>
<body>
TIY
fontVariant -
<html>
<head>
<script type="text/javascript">
function setSmallCaps()
{
document.getElementById("p1").style.fontVariant="small-caps";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph.</p>
<p>This is another example paragraph.</p>
<input type="button" onclick="setSmallCaps()" value="Display
small-caps font" />
</body>
</html>
fontWeight
Object.style.fontWeight=value
normal
bold
bolder
lighter
100
200
300
400
500
600
700
800
900
<html>
<head>
<script type="text/javascript">
function setFontWeight()
{
document.getElementById("p1").style.fontWeight="900";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph.</p>
<p>This is another example paragraph.</p>
TIY
fontWeight -
<html>
<head>
<script type="text/javascript">
function setFontWeight()
{
document.getElementById("p1").style.fontWeight="900";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph.</p>
<p>This is another example paragraph.</p>
<input type="button" onclick="setFontWeight()" value="Display bold
text" />
</body>
</html>
letterSpacing
Object.style.letterSpacing=normal|length
normal
length
<html>
<head>
<script type="text/javascript">
function changeLetterSpacing()
{
document.getElementById("p1").style.letterSpacing="3";
document.getElementById("p2").style.letterSpacing="-1";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph.</p>
<p id="p2">This is another example paragraph.</p>
<input type="button" onclick="changeLetterSpacing()"
value="Change letter-spacing" />
</body>
</html>
TIY
letterSpacing -
<html>
<head>
<script type="text/javascript">
function changeLetterSpacing()
{
document.getElementById("p1").style.letterSpacing="3";
document.getElementById("p2").style.letterSpacing="-1";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph.</p>
<p id="p2">This is another example paragraph.</p>
<input type="button" onclick="changeLetterSpacing()" value="Change
letter-spacing" />
</body>
</html>
lineHeight
Object.style.lineHeight=normal|number|length|%
normal
number
length
<html>
<head>
<script type="text/javascript">
function changeLineHeight()
{
document.getElementById("div1").style.lineHeight="2";
}
</script>
</head>
<body>
<div id="div1">
This is some text. This is some text. This is some
This is some text. This is some text. This is some
This is some text. This is some text. This is some
This is some text. This is some text. This is some
</div>
<br />
<input type="button" onclick="changeLineHeight()"
value="Change line-height" />
text.
text.
text.
text.
</body>
</html>
TIY
lineHeight -
<html>
<head>
<script type="text/javascript">
function changeLineHeight()
{
document.getElementById("div1").style.lineHeight="2";
}
</script>
</head>
<body>
<div id="div1">
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</div>
<br />
<input type="button" onclick="changeLineHeight()" value="Change
line-height" />
</body>
</html>
quotes
none
textAlign
Object.style.textAlign=left|right|center|justify
left
right
center
justify
textJustify
<html>
<head>
<script type="text/javascript">
function setTextAlign()
{
document.getElementById("p1").style.textAlign="right";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph.</p>
<input type="button" onclick="setTextAlign()"
TIY
textAlign -
<html>
<head>
<script type="text/javascript">
function setTextAlign()
{
document.getElementById("p1").style.textAlign="right";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph.</p>
<input type="button" onclick="setTextAlign()" value="Align text" />
</body>
</html>
textDecoration
Object.style.textDecoration=none|underline|overline|line-through|
blink
none
underline
overline
line-through
blink
IE Opera
<html>
<head>
<script type="text/javascript">
function setTextDecoration()
{
document.getElementById("p1").style.textDecoration="overline";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph.</p>
<input type="button" onclick="setTextDecoration()"
value="Set text-decoration" />
</body>
</html>
TIY
textDecoration -
<html>
<head>
<script type="text/javascript">
function setTextDecoration()
{
document.getElementById("p1").style.textDecoration="overline";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph.</p>
<input type="button" onclick="setTextDecoration()" value="Set
text-decoration" />
</body>
</html>
textIndent
Object.style.textIndent=length|%
length
<html>
<head>
<script type="text/javascript">
function setTextIndent()
{
document.getElementById("div1").style.textIndent="50px";
}
</script>
</head>
<body>
<div id="div1">
This is some text. This is some text. This is some
This is some text. This is some text. This is some
This is some text. This is some text. This is some
This is some text. This is some text. This is some
</div>
<br />
<input type="button" onclick="setTextIndent()"
value="Indent first line of text" />
text.
text.
text.
text.
</body>
</html>
TIY
textIndent -
<html>
<head>
<script type="text/javascript">
function setTextIndent()
{
document.getElementById("div1").style.textIndent="50px";
}
</script>
</head>
<body>
<div
This
This
This
This
id="div1">
is some text.
is some text.
is some text.
is some text.
This
This
This
This
is
is
is
is
some
some
some
some
text.
text.
text.
text.
This
This
This
This
is
is
is
is
some
some
some
some
text.
text.
text.
text.
</div>
<br />
<input type="button" onclick="setTextIndent()" value="Indent first
line of text" />
</body>
</html>
textTransform
Object.style.textTransform="none|capitalize|uppercase|lowercase|i
nherit"
none
capitalize
uppercase
lowercase
<html>
<head>
<script type="text/javascript">
function displayResult()
{
document.getElementById("p1").style.textTransform="capitalize";
}
</script>
</head>
<body>
<p id="p1">This is some text.</p>
<br />
<button type="button" onclick="displayResult()">Convert
text</button>
</body>
</html>
whiteSpace
Object.style.whiteSpace=normal|nowrap|pre
normal
pre
HTML <pre>
nowrap
<br>
<html>
<head>
<script type="text/javascript">
function removeWrapping()
{
document.getElementById("div1").style.whiteSpace="nowrap";
}
</script>
</head>
<body>
<div id="div1">
This is some text. This is some text. This is some
This is some text. This is some text. This is some
This is some text. This is some text. This is some
This is some text. This is some text. This is some
</div>
<br />
<input type="button" onclick="removeWrapping()"
value="Do not let the text wrap" />
text.
text.
text.
text.
</body>
</html>
TIY
whiteSpace -
<html>
<head>
<script type="text/javascript">
function removeWrapping()
{
document.getElementById("div1").style.whiteSpace="nowrap";
}
</script>
</head>
<body>
<div
This
This
This
This
id="div1">
is some text.
is some text.
is some text.
is some text.
This
This
This
This
is
is
is
is
some
some
some
some
text.
text.
text.
text.
This
This
This
This
is
is
is
is
some
some
some
some
text.
text.
text.
text.
</div>
<br />
<input type="button" onclick="removeWrapping()" value="Do not let the
text wrap" />
</body>
</html>
wordSpacing
Object.style.wordSpacing=normal|length
normal
length
<html>
<head>
<script type="text/javascript">
function changeWordSpacing()
{
document.getElementById("p1").style.wordSpacing="10px";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph</p>
<input type="button" onclick="changeWordSpacing()"
value="Change space between words" />
</body>
</html>
TIY
wordSpacing -
<html>
<head>
<script type="text/javascript">
function changeWordSpacing()
{
document.getElementById("p1").style.wordSpacing="10px";
}
</script>
</head>
<body>
<p id="p1">This is an example paragraph</p>
<input type="button" onclick="changeWordSpacing()" value="Change
space between words" />
</body>
</html>
acceptCharset
formObject.acceptCharset=charset
<html>
<head>
<script type="text/javascript">
function showCharset()
{
var x=document.getElementById("myForm")
alert(x.acceptCharset)
}
</script>
</head>
<body>
<form id="myForm" acceptCharset="ISO-8859-1">
Text: <input type="text" value="Hello World!">
<input type="button" onclick="showCharset()"
value="Show charset">
</form>
</body>
</html>
TIY
<html>
<head>
<script type="text/javascript">
function showCharset()
{
var x=document.getElementById("myForm")
alert(x.acceptCharset)
}
</script>
</head>
<body>
<form id="myForm" acceptCharset="ISO-8859-1">
Text: <input type="text" value="Hello World!">
<input type="button" onclick="showCharset()" value="Show charset">
</form>
</body>
</html>
accessKey
Alt + accessKey
anchorObject.accessKey=accessKey
<html>
<head>
<script type="text/javascript">
function accesskey()
{
document.getElementById('w3').accessKey="w"
}
</script>
</head>
<body onload="accesskey()">
<a id="w3" href="http://www.w3school.com.cn/">W3School.com.cn</a>
</body>
</html>
TIY
<html>
<head>
<script type="text/javascript">
function accesskey()
{
document.getElementById('w3').accessKey="w"
document.getElementById('w3dom').accessKey="d"
}
</script>
</head>
<body onload="accesskey()">
<p><a id="w3"
href="http://www.w3school.com.cn/">W3School.com.cn</a> Alt
+ w </p>
<p><a id="w3dom" href="http://www.w3school.com.cn/htmldom/">HTML
DOM</a> Alt + d </p>
</body>
</html>
action action
action
formObject.action=URL
action URL
<html>
<head>
<script type="text/javascript">
function changeAction()
{
var x=document.getElementById("myForm")
alert("Original action: " + x.action)
x.action="index.asp"
alert("New action: " + x.action)
x.submit()
}
</script>
</head>
<body>
<form id="myForm" action="js_examples.asp">
Name: <input type="text" value="Mickey Mouse" />
<input type="button" onclick="changeAction()"
value="Change action attribute and submit form" />
</form>
</body>
</html>
TIY
action
<html>
<head>
<script type="text/javascript">
function changeAction()
{
var x=document.getElementById("myForm")
align iframe
iframeObject.align=left|right|top|middle|bottom
iframe
<html>
<body>
<iframe src="frame_a.htm" id="frame1"></iframe>
<p>Some text. Some text. Some text. Some text.</p>
<script type="text/javascript">
document.getElementById("frame1").align="right";
</script>
</body>
</html>
TIY
<iframe>
<html>
<body>
<img id="compman" src="/i/eg_compman.gif" alt="Computerman" />
<p>Some text. Some text. Some text. Some text. Some text. Some text.
Some text. Some text. Some text. Some text.</p>
<script type="text/javascript">
document.getElementById("compman").align="right";
</script>
</body>
</html>
alt
areaObject.alt=alternate_text
"Venus"
<html>
<body>
<img src="planets.gif"
width="145" height="126"
usemap="#planetmap" />
<map name="planetmap">
<area id="venus" shape="circle"
coords="124,58,8"
alt="The planet Venus"
href="venus.htm" />
</map>
<p>Alternate text for "Venus" is:
<script type="text/javascript">
x=document.getElementById('venus');
document.write(x.alt);
</script>
</p>
</body>
</html>
TIY
<html>
<body>
<img src="/i/eg_planets.jpg"
usemap="#planetmap" />
<map name="planetmap">
<area id="venus" shape="circle"
coords="180,139,14"
alt="The planet Venus"
href="/example/hdom/venus.html" />
</map>
<p>"Venus"
<script type="text/javascript">
x=document.getElementById('venus');
document.write(x.alt);
</script>
</p>
</body>
</html>
border
imageObject.border=pixels
<html>
<head>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("compman").border="3"
}
</script>
</head>
<body>
<img id="compman" src="compman.gif" alt="Computerman" />
<br /><br />
<input type="button" onclick="changeBorder()"
value="Change border" />
</body>
</html>
TIY
<html>
<head>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("compman").border="3"
}
</script>
</head>
<body>
<img id="compman" src="/i/eg_compman.gif" alt="Computerman" />
<br /><br />
<input type="button" onclick="changeBorder()" value="Change border"
/>
</body>
</html>
charset
anchorObject.charset=charset
<html>
<body>
<p>
<a id="myAnchor"
href="http://www.w3school.com.cn">W3School.com.cn</a>
</p>
<script type="text/javascript">
x=document.getElementById("myAnchor");
x.charset="ISO-8859-1";
</script>
</body>
</html>
TIY
<html>
<body>
<p>
<a id="myAnchor"
href="http://www.w3school.com.cn">W3School.com.cn</a>
</p>
<script type="text/javascript">
x=document.getElementById("myAnchor");
x.charset="ISO-8859-1";
document.write(x.charset);
</script>
</body>
</html>
checked checkbox
checkboxObject.checked=true|false
checkbox onclick
onchange
checkbox
<html>
<head>
<script type="text/javascript">
function check()
{
document.getElementById("check1").checked=true
}
function uncheck()
{
document.getElementById("check1").checked=false
}
</script>
</head>
<body>
<form>
<input type="checkbox" id="check1" />
<input type="button" onclick="check()" value="Check Checkbox" />
<input type="button" onclick="uncheck()" value="Uncheck Checkbox" />
</form>
</body>
</html>
TIY
checkbox
<html>
<head>
<script type="text/javascript">
function check()
{
document.getElementById("myCheck").checked=true
}
function uncheck()
{
document.getElementById("myCheck").checked=false
}
</script>
</head>
<body>
<form>
<input type="checkbox" id="myCheck" />
<input type="button" onclick="check()" value="" />
<input type="button" onclick="uncheck()" value="" />
</form>
</body>
</html>
checkbox
<html>
<head>
<script type="text/javascript">
function createOrder()
{
coffee=document.forms[0].coffee
txt=""
for (i=0;i<coffee.length;++ i)
{
if (coffee[i].checked)
{
txt=txt + coffee[i].value + " "
}
}
document.getElementById("order").value=" " + txt
}
</script>
</head>
<body>
<p></p>
<form>
<input type="checkbox" name="coffee" value=""><br />
<input type="checkbox" name="coffee" value=""><br />
<br />
<input type="button" onclick="createOrder()" value="">
<br /><br />
<input type="text" id="order" size="50">
</form>
</body>
</html>
Checkbox -
<html>
<head>
<script type="text/javascript">
function convertToUcase()
{
document.getElementById("fname").value=document.getElementById("f
name").value.toUpperCase()
document.getElementById("lname").value=document.getElementById("l
name").value.toUpperCase()
}
</script>
</head>
<body>
<form name="form1">
<input type="text" id="fname" size="20" />
<br /><br />
<input type="text" id="lname" size="20" />
<br /><br />
coords
anchorObject.coords=coordinates
<html>
<body>
<img src="planets.gif"
width="145" height="126"
usemap="#planetmap" />
<map name="planetmap">
<area id="venus" shape="circle"
coords="124,58,8"
alt="Venus"
href="venus.htm" />
</map>
<p>Venus coordinates:
<script type="text/javascript">
x=document.getElementById("venus");
document.write(x.coords);
</script>
</p>
</body>
</html>
TIY
<html>
<body>
<img src="/i/eg_planets.jpg"
usemap="#planetmap" />
<map name="planetmap">
<area id="venus" shape="circle"
coords="180,139,14"
alt="Venus"
href="/example/hdom/venus.html" />
</map>
<p>Venus coords
<script type="text/javascript">
x=document.getElementById("venus");
document.write(x.coords);
</script>
</p>
</body>
</html>
cols
framesetObject.cols=col1,col2,col3....
HTML
50%
<html>
<frameset cols="50%,50%">
<frame src="frame_cols.htm">
<frame src="frame_a.htm">
</frameset>
</html>
HTML "frame_cols.htm" HTML "frame_a.htm"
"frame_cols.htm"
<html>
<head>
<script type="text/javascript">
function changeCols()
{
parent.document.getElementById("main").cols="30%,70%"
}
function restoreCols()
{
parent.document.getElementById("main").cols="50%,50%"
}
</script>
</head>
<body>
<input type="button" onclick="changeCols()"
value="Change column size" />
<input type="button" onclick="restoreCols()"
value="Restore column size" />
</body>
</html>
complete
true fasle
imageObject.complete
<html>
<head>
<script type="text/javascript">
function alertComplete()
{
alert(document.getElementById("compman").complete)
}
</script>
</head>
<body onload="alertComplete()">
<img id="compman" src="compman.gif" alt="Computerman"
width="107" height="98" />
</body>
</html>
TIY
<html>
<head>
<script type="text/javascript">
function alertComplete()
{
alert("Image loaded=" +
document.getElementById("compman").complete)
}
</script>
</head>
<body onload="alertComplete()">
<img id="compman" src="/i/eg_compman.gif" alt="Computerman" />
</body>
</html>
iframeObject.contentDocument
iframe <h2>
<html>
<head>
<script type="text/javascript">
function getTextNode()
{
var x=document.getElementById("frame1").contentDocument;
alert(x.getElementsByTagName("h2")[0].childNodes[0].nodeValue);
}
</script>
</head>
<body>
<iframe src="frame_a.htm" id="frame1"></iframe>
<br /><br />
<input type="button" onclick="getTextNode()" value="Get text" />
</body>
</html>
TIY
iframe
<html>
<head>
<script type="text/javascript">
function getText()
{
var x=document.getElementById("frame1").contentDocument;
alert(x.getElementsByTagName("h3")[0].childNodes[0].nodeValue);
}
</script>
</head>
<body>
<iframe src="/example/hdom/frame_a.html" id="frame1" ></iframe>
<br /><br />
<input type="button" onclick="getText()" value="Get text" />
</body>
</html>
defaultChecked checked
checkbox true false
checkboxObject.defaultChecked
checked
<html>
<body>
<form>
<input type="checkbox" id="myCheck" checked="checked" />
</form>
<script type="text/javascript">
alert(document.getElementById("myCheck").defaultChecked)
</script>
</body>
</html>
TIY
checkbox
<html>
<body>
<form>
<input type="checkbox" id="myCheck" checked="checked" />
</form>
<script type="text/javascript">
alert(document.getElementById("myCheck").defaultChecked)
</script>
</body>
</html>
checkbox
<html>
<head>
<script type="text/javascript">
function check()
{
document.getElementById("myCheck").checked=true
}
function uncheck()
{
document.getElementById("myCheck").checked=false
}
</script>
</head>
<body>
<form>
<input type="checkbox" id="myCheck" />
<input type="button" onclick="check()" value="" />
<input type="button" onclick="uncheck()" value="" />
</form>
</body>
</html>
disabled
buttonObject.disabled=true|false
<html>
<head>
<script type="text/javascript">
function disableButton()
{
document.getElementById("myButton").disabled=true
}
</script>
</head>
<body>
<form>
<button id="myButton" onClick="disableButton()">
Click Me!</button>
</form>
</body>
</html>
TIY
id +
<html>
<head>
<script type="text/javascript">
function alertId()
{
var txt="Id: " + document.getElementById("myButton").id
txt=txt + ", type: " + document.getElementById("myButton").type
alert(txt)
document.getElementById("myButton").disabled=true
}
</script>
</head>
<body>
<form>
<button id="myButton" onClick="alertId()"></button>
</form>
</body>
</html>
enctype MIME
enctype
"application/x-www-form-urlencoded"
input type "file" "multipart/form-data"
formObject.encoding=encoding
<html>
<head>
<script type="text/javascript">
function showEnctype()
{
var x=document.getElementById("myForm")
alert(x.enctype)
}
</script>
</head>
<body>
<form id="myForm" enctype="application/x-www-form-urlencoded">
Name: <input type="text" value="Mickey Mouse" />
<input type="button" onclick="showEnctype()"
value="Show enctype" />
</form>
</body>
</html>
TIY
<html>
<head>
<script type="text/javascript">
function showEnctype()
{
var x=document.getElementById("myForm")
alert(x.enctype)
}
</script>
</head>
<body>
<form id="myForm" enctype="application/x-www-form-urlencoded">
Name: <input type="text" value="Mickey Mouse" />
<input type="button" onclick="showEnctype()"
value="Show enctype" />
</form>
</body>
</html>
form
form null
buttonObject.form
id
<html>
<body>
<form id="form1">
<button id="button1">Click me!</button>
</form>
<p>The form containing the button is:
<script type="text/javascript">
x=document.getElementById('button1');
document.write(x.form.id);
</script></p>
</body>
</html>
TIY
id
<!DOCTYPE html>
<html>
<body>
<form id="form1">
<button id="button1" type="button"></button>
</form>
<p> id
<script>
document.write(document.getElementById("button1").form.id);
</script>
</p>
</body>
</html>
hash URL
areaObject.hash=anchorname
</html>
TIY
URL
<html>
<head>
<script type="text/javascript">
function changeLink()
{
document.getElementById('venus').hash="bottom"
}
</script>
</head>
<body>
<img src="/i/eg_planets.jpg"
usemap="#planetmap" />
<map name="planetmap">
<area
id="venus"
shape="circle"
coords="180,139,14"
href ="/example/hdom/venus2.html#top"
alt="Venus" />
</map>
<input type="button" onclick="changeLink()" value="" />
</body>
</html>
height iframe
iframeObject.height=pixels
iframe
<html>
<head>
<script type="text/javascript">
function changeHeight()
{
document.getElementById("frame1").height="200";
}
</script>
</head>
<body>
<iframe src="frame_a.htm" id="frame1" height="100"></iframe>
<br /><br />
<input type="button" onclick="changeHeight()"
value="Change height" />
</body>
</html>
TIY
iframe
<html>
<head>
<script type="text/javascript">
function changeSize()
{
document.getElementById("frame1").height="300";
document.getElementById("frame1").width="300";
}
function restoreSize()
{
document.getElementById("frame1").height="200";
document.getElementById("frame1").width="200";
}
</script>
</head>
<body>
<iframe src="/example/hdom/frame_a.html" id="frame1" height="200"
width="200"></iframe>
<br /><br />
<input type="button" onclick="changeSize()" value="Change size" />
<input type="button" onclick="restoreSize()" value="Restore size" />
</body>
</html>
host URL
areaObject.host=host
"Venus"
<html>
<body>
<img src="planets.gif"
width="145" height="126"
usemap="#planetmap" />
<map name="planetmap">
TIY
<html>
<body>
<img src="/i/eg_planets.jpg"
usemap="#planetmap" />
<map name="planetmap">
<area
id="venus"
shape="circle"
coords="180,139,14"
href ="/example/html/venus.html"
alt="Venus" />
</map>
<p>"Venus" hostname port
<script type="text/javascript">
x=document.getElementById('venus');
document.write(x.host);
</script>
</p>
</body>
</html>
href URL
anchorObject.href=URL
URL target
<html>
<head>
<script type="text/javascript">
function changeLink()
{
document.getElementById('myAnchor').innerHTML="W3School";
document.getElementById('myAnchor').href="http://www.w3school.com.
cn";
document.getElementById('myAnchor').target="_blank";
}
</script>
</head>
<body>
<a id="myAnchor" href="http://www.microsoft.com">Microsoft</a>
<input type="button" onclick="changeLink()" value="Change link">
</body>
</html>
TIY
URL target
<html>
<head>
<script type="text/javascript">
function changeLink()
{
document.getElementById('myAnchor').innerHTML=" W3School"
document.getElementById('myAnchor').href="http://www.w3school.com.
cn"
document.getElementById('myAnchor').target="_blank"
}
</script>
</head>
<body>
<a id="myAnchor" href="http://www.microsoft.com"> Microsoft</a>
<input type="button" onclick="changeLink()" value="">
<p> URL target target
"_self" target
"_blank"</p>
</body>
</html>
hreflang
anchorObject.hreflang=languagecode
<html>
<body>
<p><a id="myAnchor" hreflang="zh-cn"
href="http://www.w3school.com.cn">W3School.com.cn</a></p>
<script type="text/javascript">
x=document.getElementById("myAnchor");
document.write(x.hreflang);
</script>
</body>
</html>
TIY
<html>
<body>
<p><a id="myAnchor" hreflang="zh-cn"
href="http://www.w3school.com.cn">W3School.com.cn</a></p>
<script type="text/javascript">
x=document.getElementById("myAnchor");
document.write(x.hreflang);
</script>
</body>
</html>
HTML DOM id
id id
anchorObject.id=ide
id
<html>
<body>
<p><a id="myAnchor"
href="http://www.w3school.com.cn">Visit W3School.com.cn</a></p>
<script type="text/javascript">
x=document.getElementById("myAnchor");
document.write(x.id);
</script>
</body>
</html>
TIY
id
<html>
<body>
<p><a id="myAnchor" href="http://www.w3school.com.cn">Visit
W3School.com.cn</a></p>
<script type="text/javascript">
x=document.getElementById("myAnchor");
document.write(x.id);
</script>
</body>
</html>
isMap
imageObject.isMap
<html>
<body>
<img id="planets" src="planets.gif"
width="145" height="126"
usemap="#planetmap" />
<map name="planetmap">
<area id="venus" shape="circle"
coords="124,58,8"
alt="The planet Venus"
href="venus.htm" />
</map>
<p>Is the image a server-side image map?
<script type="text/javascript">
x=document.getElementById('planets');
document.write(x.isMap);
</script>
</p>
</body>
</html>
TIY
<html>
<body>
<img id="planets"
src="/i/eg_planets.jpg"
usemap="#planetmap" />
<map name="planetmap">
<area shape="circle"
coords="180,139,14"
href ="/example/html/venus.html"
target ="_blank"
alt="Venus" />
</map>
<p>
<script type="text/javascript">
x=document.getElementById('planets');
document.write(x.isMap);
</script>
</p>
</body>
</html>
innerHTML
anchorObject.innerHTML=text
URL target
<html>
<head>
<script type="text/javascript">
function changeLink()
{
document.getElementById('myAnchor').innerHTML="W3School";
document.getElementById('myAnchor').href="http://www.w3school.com.
cn";
document.getElementById('myAnchor').target="_blank";
}
</script>
</head>
<body>
<a id="myAnchor" href="http://www.microsoft.com">Microsoft</a>
<input type="button" onclick="changeLink()" value="Change link">
</body>
</html>
TIY
URL target
<html>
<head>
<script type="text/javascript">
function changeLink()
{
document.getElementById('myAnchor').innerHTML=" W3School"
document.getElementById('myAnchor').href="http://www.w3school.com.
cn"
document.getElementById('myAnchor').target="_blank"
}
</script>
</head>
<body>
<a id="myAnchor" href="http://www.microsoft.com"> Microsoft</a>
length
formObject.length
<html>
<body>
<form id="myForm" method="get">
Name: <input type="text" size="20" value="Peter Griffin" /><br />
Text: <input type="text" size="20" value="Hello World" />
</form>
<script type="text/javascript">
document.write("Number of elements in myForm: ");
document.write(document.getElementById('myForm').length);
</script>
</body>
</html>
TIY
<html>
<body>
<form id="myForm" method="get">
Name: <input type="text" size="20" value="Peter Griffin" /><br />
Text: <input type="text" size="20" value="Hello World" />
</form>
<script type="text/javascript">
document.write("Number of elements in myForm: ");
document.write(document.getElementById('myForm').length);
</script>
</body>
</html>
iframeObject.longDesc=URL
<html>
<body>
<iframe src="frame_a.htm" id="frame1"
longdesc="frame_description.htm"></iframe>
<br />
<script type="text/javascript">
x=document.getElementById("frame1");
document.write("Description for frame contents: ");
document.write('<a href="' + x.longDesc + '">Description</a>');
</script>
</body>
</html>
TIY
<iframe> longdesc
<html>
<body>
<iframe src="/example/hdom/frame_a.html" id="frame1"
longdesc="/example/hdom/frame_description.html"></iframe>
<br />
<script type="text/javascript">
x=document.getElementById("frame1");
document.write("Description for frame contents: ");
document.write('<a href="' + x.longDesc + '">Description</a>');
</script>
</body>
</html>
lowsrc URL
imageObject.lowsrc=URL
<html>
<body>
<img id="compman" src="compman.gif"
lowsrc="compman_lowres.gif" alt="Computerman" />
<br />
<script type="text/javascript">
var x=document.getElementById("compman");
document.write('<a href="' + x.lowsrc + '">Low resolution</a>');
</script>
</body>
</html>
TIY
<html>
<body>
<img id="compman" src="/i/eg_compman.gif"
lowsrc="/i/eg_compman_lowres.gif" alt="Computerman" />
<br />
<script type="text/javascript">
var x=document.getElementById("compman");
document.write('<a href="' + x.lowsrc + '">Low resolution
version</a>');
</script>
</body>
</html>
marginHeight
iframeObject.marginHeight=pixels
iframe
<html>
<body>
<iframe src="frame_a.htm" id="frame1" marginheight="50"></iframe>
<br />
<script type="text/javascript">
x=document.getElementById("frame1");
document.write("Top and bottom margins of the iframe are: ");
document.write(x.marginHeight);
</script>
</body>
</html>
TIY
iframe
<html>
<body>
<iframe src="/example/hdom/frame_a.html" id="frame1"
marginheight="50"></iframe>
<br /><br />
<script type="text/javascript">
x=document.getElementById("frame1");
document.write("Top and bottom margins of the iframe are: ");
document.write(x.marginHeight);
</script>
</body>
</html>
marginWidth
iframeObject.marginWidth=pixels
iframe
<html>
<body>
<iframe src="frame_a.htm" id="frame1" marginwidth="50"></iframe>
<br /><br />
<script type="text/javascript">
x=document.getElementById("frame1");
document.write("Left and right margins of the iframe are: ");
document.write(x.marginWidth);
</script>
</body>
</html>
TIY
iframe
<html>
<body>
<iframe src="/example/hdom/frame_a.html" id="frame1"
marginwidth="50"></iframe>
<br /><br />
<script type="text/javascript">
x=document.getElementById("frame1");
document.write("Left and right margins of the iframe are: ");
document.write(x.marginWidth);
</script>
</body>
</html>
maxLength
passwordObject.maxLength=number_of_chars
<html>
<head>
<script type="text/javascript">
function alertLength()
{
alert(document.getElementById("password1").maxLength)
}
</script>
</head>
<body>
<form>
<input type="password" id="password1" maxLength="8" />
<input type="button" id="button1" onclick="alertLength()"
value="Alert maxLength" />
</form>
</body>
</html>
TIY
<html>
<head>
<script type="text/javascript">
function alertLength()
{
alert(document.getElementById("password1").maxLength)
}
</script>
</head>
<body>
<form>
<input type="password" id="password1" maxLength="8" />
<input type="button" id="button1" onclick="alertLength()"
value="Alert maxLength" />
</form>
</body>
</html>
media
linkObject.media=device
screen
tty
tv
TV
projection
handheld
braille
aural
all
link
<html>
<head>
<link rel="stylesheet" type="text/css" media="screen"
id="style1" href="try_dom_link.css" />
</head>
<body>
<script type="text/javascript">
x=document.getElementById("style1");
document.write("Intended media type=" + x.media);
</script>
</body>
</html>
TIY
link
<html>
<head>
<link rel="stylesheet" type="text/css" media="screen"
id="style1" href="/example/hdom/try_dom_link.css" />
</head>
<body>
<script type="text/javascript">
x=document.getElementById("style1");
document.write("Intended media type=" + x.media);
</script>
</body>
</html>
method HTTP
formObject.method=get|post
HTTP
<html>
<head>
<script type="text/javascript">
function showMethod()
{
var x=document.getElementById("myForm")
alert(x.method)
}
</script>
</head>
<body>
<form id="myForm" method="post">
Name: <input type="text" size="20" value="Mickey Mouse" />
<input type="button" onclick="showMethod()" value="Show method" />
</form>
</body>
</html>
TIY
HTTP
<html>
<head>
<script type="text/javascript">
function showMethod()
{
var x=document.getElementById("myForm")
alert(x.method)
}
</script>
</head>
<body>
<form id="myForm" method="post">
<input type="text" value="" />
<input type="button" onclick="showMethod()" value=" method" />
</form>
</body>
</html>
multiple
Opera 9
selectObject.multiple=true|false
TIY
<html>
<head>
<script type="text/javascript">
function selectMultiple()
{
document.getElementById("mySelect").multiple=true
}
</script>
</head>
<body>
<form>
<select id="mySelect" size="4">
<option></option>
<option></option>
<option></option>
<option></option>
</select>
<input type="button" onclick="selectMultiple()" value="">
</form>
<p>
</p>
</body>
</html>
name
anchorObject.name=name
<html>
<body>
<p><a id="myAnchor" name="myAnchor"
href="http://www.w3school.com.cn">Visit W3School.com.cn</a></p>
<script type="text/javascript">
x=document.getElementById("myAnchor");
document.write(x.name);
</script>
</body>
</html>
TIY
<html>
<body>
<p><a id="myAnchor" name="myAnchor"
href="http://www.w3school.com.cn">Visit W3School.com.cn</a></p>
<script type="text/javascript">
x=document.getElementById("myAnchor");
document.write(x.name);
</script>
</body>
</html>
noHref
areaObject.noHref=true|false
<area> nohref
<area> href nohref
"Venus" "noHref"
<html>
<body>
<img src="planets.gif"
width="145" height="126"
usemap="#planetmap" />
<map name="planetmap">
<area id="venus" shape="circle"
coords="124,58,8"
alt="Venus"
href="venus.htm" />
</map>
<p>noHref status:
<script type="text/javascript">
x=document.getElementById('venus');
document.write(x.noHref);
</script>
</p>
</script>
</body>
</html>
TIY
noHref
<html>
<body>
<img src="/i/eg_planets.jpg"
usemap="#planetmap" />
<map name="planetmap">
<area
id="venus"
shape="circle"
coords="180,139,14"
href ="/example/html/venus.html"
alt="Venus" />
</map>
<p>noHref
<script type="text/javascript">
x=document.getElementById('venus');
document.write(x.noHref);
</script>
</p>
</script>
</body>
</html>
pathname link-URL
areaObject.pathname=pathnamee
"Venus" link-URL
<html>
<body>
<img src="planets.gif"
width="145" height="126"
usemap="#planetmap" />
<map name="planetmap">
<area id="venus" shape="circle"
coords="124,58,8"
alt="Venus"
href="venus.htm" />
</map>
<p>Venus' pathname:
<script type="text/javascript">
x=document.getElementById('venus');
document.write(x.pathname);
</script>
</p>
</body>
</html>
TIY
link-URL
<html>
<body>
<img src="/i/eg_planets.jpg"
usemap="#planetmap" />
<map name="planetmap">
<area
id="venus"
shape="circle"
coords="180,139,14"
href ="/example/html/venus.html"
alt="Venus" />
</map>
<p>Venus
<script type="text/javascript">
x=document.getElementById('venus');
document.write(x.pathname);
</script>
</p>
</body>
</html>
protocol link-URL
areaObject.protocol=protocol
"Venus" link-URL
<html>
<body>
<img src="planets.gif"
width="145" height="126"
usemap="#planetmap" />
<map name="planetmap">
<area id="venus" shape="circle"
coords="124,58,8"
alt="Venus"
href="venus.htm" />
</map>
<p>Venus' protocol:
<script type="text/javascript">
x=document.getElementById('venus');
document.write(x.protocol);
</script>
</p>
</body>
</html>
TIY
link-URL
<html>
<body>
<img src="/i/eg_planets.jpg"
usemap="#planetmap" />
<map name="planetmap">
<area
id="venus"
shape="circle"
coords="180,139,14"
href ="/example/html/venus.html"
alt="Venus" />
</map>
<p>Venus
<script type="text/javascript">
x=document.getElementById('venus');
document.write(x.protocol);
</script>
</p>
</body>
</html>
readOnly
passwordObject.readOnly=true|false
<html>
<head>
<script type="text/javascript">
function makeReadOnly()
{
document.getElementById("password1").readOnly=true
}
</script>
</head>
<body>
<form>
<input type="password" id="password1" value="thgrt456" />
<input type="button" onclick="makeReadOnly()"
value="Make read-only" />
</form>
</body>
</html>
TIY
<html>
<head>
<script type="text/javascript">
function makeReadOnly()
{
document.getElementById("password1").readOnly=true
}
</script>
</head>
<body>
<form>
<input type="password" id="password1" value="thgrt456" />
<input type="button" onclick="makeReadOnly()" value="Make read-only"
/>
</form>
</body>
</html>
rel
rel rev <a>
rel (relationship) rev (reverse)
anchorObject.rel=relationship
appendix
alternate
bookmark
chapter
contents
copyright
glossary
index
next
prev
section
start
subsection
head
toc
parent
child
<html>
<body>
<p><a id="myAnchor" rel="index"
href="http://www.w3school.com.cn">Visit W3School.com.cn</a></p>
<script type="text/javascript">
x=document.getElementById("myAnchor");
document.write(x.rel);
</script>
</body>
</html>
TIY
<html>
<body>
<p><a id="myAnchor" rel="index"
href="http://www.w3school.com.cn">Visit W3School.com.cn</a></p>
<script type="text/javascript">
x=document.getElementById("myAnchor");
document.write(x.rel);
</script>
</body>
</html>
rev
rel rev <a>
rel (relationship) rev (reverse)
anchorObject.rev=relationship
appendix
alternate
bookmark
chapter
contents
copyright
glossary
index
next
prev
section
start
subsection
head
toc
parent
child
<html>
<body>
<p><a id="myAnchor" rev="subsection"
href="/htmldom/prop_anchor_rev.asp">
HTML DOM rev Property</a></p>
<script type="text/javascript">
x=document.getElementById("myAnchor");
document.write(x.rev);
</script>
</body>
</html>
TIY
<html>
<body>
<p><a id="myAnchor" rev="subsection"
href="/htmldom/prop_anchor_rev.asp">
HTML DOM rev Property</a></p>
<script type="text/javascript">
x=document.getElementById("myAnchor");
document.write(x.rev);
</script>
</body>
</html>
rows
framesetObject.rows=row1,row2,row3....
HTML
50%
<html>
<frameset rows="50%,50%">
<frame src="frame_rows.htm">
<frame src="frame_a.htm">
</frameset>
</html>
HTML "frame_rows.htm" HTML "frame_a.htm"
"frame_rows.htm"
<html>
<head>
<script type="text/javascript">
function changeRows()
{
parent.document.getElementById("main").rows="30%,70%"
}
function restoreRows()
{
parent.document.getElementById("main").rows="50%,50%"
}
</script>
</head>
<body>
<form>
<input type="button" onclick="changeRows()"
value="Change row size" />
<input type="button" onclick="restoreRows()"
value="Restore row size" />
</form>
</body>
</html>
TIY
<html>
<frameset id="main" rows="50%,50%">
<frame id="leftFrame" src="/example/hdom/frame_rows.html">
<frame id="rightFrame" src="/example/hdom/frame_a.html" >
</frameset>
</html>
scrolling iframe
iframeObject.scrolling=auto|yes|no
iframe
<html>
<head>
<script type="text/javascript">
function addScrollbars()
{
document.getElementById("frame1").scrolling="yes";
}
function removeScrollbars()
{
document.getElementById("frame1").scrolling="no";
}
</script>
</head>
<body>
<iframe src="frame_a.htm" id="frame1" ></iframe><br />
<input type="button" onclick="addScrollbars()"
value="Add Scrollbars" />
<input type="button" onclick="removeScrollbars()"
value="Remove Scrollbars" />
</body>
</html>
TIY
<iframe>
<html>
<head>
<script type="text/javascript">
function addScrollbars()
{
document.getElementById("frame1").scrolling="yes";
}
function removeScrollbars()
{
document.getElementById("frame1").scrolling="no";
}
</script>
</head>
<body>
<iframe src="/example/hdom/frame_a.html" id="frame1" ></iframe>
<br />
<input type="button" onclick="addScrollbars()" value="Add
Scrollbars" />
<input type="button" onclick="removeScrollbars()" value="Remove
Scrollbars" />
</body>
</html>
selectedIndex
selectObject.selectedIndex=number
<html>
<head>
<script type="text/javascript">
function getIndex()
{
var x=document.getElementById("mySelect")
alert(x.selectedIndex)
}
</script>
</head>
<body>
<form>
Select your favorite fruit:
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
<br /><br />
<input type="button" onclick="getIndex()"
value="Alert index of selected option">
</form>
</body>
</html>
TIY
<html>
<head>
<script type="text/javascript">
function getIndex()
{
var x=document.getElementById("mySelect")
alert(x.selectedIndex)
}
</script>
</head>
<body>
<form>
Select your favorite fruit:
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
<br /><br />
<input type="button" onclick="getIndex()" value="Alert index of
selected option">
</form>
</body>
</html>
<html>
<head>
<script type="text/javascript">
function changeText()
{
var x=document.getElementById("mySelect")
x.options[x.selectedIndex].text="Melon"
}
</script>
</head>
<body>
<form>
Select your favorite fruit:
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
<br /><br />
<input type="button" onclick="changeText()" value="Set text of
selected option">
</form>
</body>
</html>
<html>
<head>
<script type="text/javascript">
function removeOption()
{
var x=document.getElementById("mySelect")
x.remove(x.selectedIndex)
}
</script>
</head>
<body>
<form>
<select id="mySelect">
<option></option>
<option></option>
<option></option>
<option></option>
</select>
<input type="button" onclick="removeOption()" value="">
</form>
</body>
</html>
shape
anchorObject.shape=RECT|CIRCLE|POLY|DEFAULT
<html>
<body>
<img src="planets.gif"
width="145" height="126"
usemap="#planetmap" />
<map name="planetmap">
<area id="venus" shape="circle"
coords="124,58,8"
alt="Venus"
href="venus.htm" />
</map>
<p>Shape of Venus-link:
<script type="text/javascript">
x=document.getElementById("venus");
document.write(x.shape);
</script>
</p>
</body>
</html>
TIY
<html>
<body>
<img src="/i/eg_planets.jpg"
usemap="#planetmap" />
<map name="planetmap">
<area id="venus" shape="circle"
coords="180,139,14"
alt="Venus"
href="/example/hdom/venus.html" />
</map>
<p>Venus area shape
<script type="text/javascript">
x=document.getElementById("venus");
document.write(x.shape);
</script>
</p>
</body>
</html>
size
passwordObject.size=number_of_chars
<html>
<head>
<script type="text/javascript">
function changeSize()
{
document.getElementById("password1").size=40
}
</script>
</head>
<body>
<form>
<input type="password" id="password1" />
<input type="button" id="button1" onclick="changeSize()"
value="Change size of the password field" />
</form>
</body>
</html>
TIY
<html>
<head>
<script type="text/javascript">
function changeSize()
{
document.getElementById("password1").size=40
}
</script>
</head>
<body>
<form>
<input type="password" id="password1" />
<input type="button" id="button1" onclick="changeSize()"
value="Change size of the password field" />
</form>
</body>
</html>
iframeObject.src=URL
<html>
<head>
<script type="text/javascript">
function changeSource()
{
document.getElementById("frame1").src="frame_c.htm"
document.getElementById("frame2").src="frame_d.htm"
}
</script>
</head>
<body>
<iframe src="frame_a.htm" id="frame1"></iframe>
<iframe src="frame_b.htm" id="frame2"></iframe>
<br /><br />
TIY
<html>
<head>
<script type="text/javascript">
function changeSource()
{
document.getElementById("frame1").src="/example/hdom/frame_c.html
"
document.getElementById("frame2").src="/example/hdom/frame_d.html
"
}
</script>
</head>
<body>
<iframe src="/example/hdom/frame_a.html" id="frame1"></iframe>
<iframe src="/example/hdom/frame_b.html" id="frame2"></iframe>
<br /><br />
<input type="button" onclick="changeSource()" value="
source">
</body>
</html>
tabIndex tab
anchorObject.tabIndex=tabIndex
tab
<html>
<head>
<script type="text/javascript">
function changeTabIndex()
{
document.getElementById('1').tabIndex="3"
document.getElementById('2').tabIndex="2"
document.getElementById('3').tabIndex="1"
}
</script>
</head>
<body>
<p><a id="1" href="http://www.w3school.com.cn">1</a></p>
<p><a id="2" href="http://www.w3school.com.cn">2</a></p>
<p><a id="3" href="http://www.w3school.com.cn">3</a></p>
<input type="button" onclick="changeTabIndex()"
value="Change TabIndex" />
</body>
</html>
TIY
tab
<html>
<head>
<script type="text/javascript">
function changeTabIndex()
{
document.getElementById('1').tabIndex="3"
document.getElementById('2').tabIndex="2"
document.getElementById('3').tabIndex="1"
}
</script>
</head>
<body>
<p><a id="1" href="http://www.w3school.com.cn">1</a></p>
<p><a id="2" href="http://www.w3school.com.cn">2</a></p>
<p><a id="3" href="http://www.w3school.com.cn">3</a></p>
<input type="button" onclick="changeTabIndex()"
value="Change TabIndex" />
<p>Try navigating the links by using the "Tab" button on you keyboard
before and after pushing the "Change TabIndex" button.</p>
</body>
</html>
target
anchorObject.target=_blank|_parent|_self|_top
_blank -
_self -
_parent -
_top - ,
URL target
<html>
<head>
<script type="text/javascript">
function changeLink()
{
document.getElementById('myAnchor').innerHTML="W3School";
document.getElementById('myAnchor').href="http://www.w3school.com.
cn";
document.getElementById('myAnchor').target="_blank";
}
</script>
</head>
<body>
<a id="myAnchor" href="http://www.microsoft.com">Microsoft</a>
<input type="button" onclick="changeLink()" value="Change link">
</body>
</html>
TIY
URL target
<html>
<head>
<script type="text/javascript">
function changeLink()
{
document.getElementById('myAnchor').innerHTML=" W3School"
document.getElementById('myAnchor').href="http://www.w3school.com.
cn"
document.getElementById('myAnchor').target="_blank"
}
</script>
</head>
<body>
<a id="myAnchor" href="http://www.microsoft.com"> Microsoft</a>
<input type="button" onclick="changeLink()" value="">
<p> URL target target
"_self" target
"_blank"</p>
</body>
</html>
text
<option>
optionObject.text=sometext
<html>
<head>
<script type="text/javascript">
function getOptions()
{
var x=document.getElementById("mySelect");
var y="";
for (i=0;i<x.length;i++)
{
y+=x.options[i].text;
y+="<br />";
}
document.write(y);
}
</script>
</head>
<body>
<form>
<select id="mySelect">
<option></option>
<option></option>
<option></option>
<option></option>
</select>
<br /><br />
<input type="button" onclick="getOptions()" value="">
</form>
</body>
</html>
TIY
<html>
<head>
<script type="text/javascript">
function getOptions()
{
var x=document.getElementById("mySelect");
var y="";
for (i=0;i<x.length;i++)
{
y+=x.options[i].text;
y+="<br />";
}
document.write(y);
}
</script>
</head>
<body>
<form>
<select id="mySelect">
<option></option>
<option></option>
<option></option>
<option></option>
</select>
<br /><br />
<input type="button" onclick="getOptions()" value="">
</form>
</body>
</html>
<html>
<head>
<script type="text/javascript">
function changeText()
{
var x=document.getElementById("mySelect")
x.options[x.selectedIndex].text="Melon"
}
</script>
</head>
<body>
<form>
Select your favorite fruit:
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
<br /><br />
<input type="button" onclick="changeText()" value="Set text of
selected option">
</form>
</body>
</html>
type MIME
anchorObject.type=type
MIME
<html>
<body>
<p><a id="myAnchor" type="text/html"
href="http://www.w3school.com.cn">W3School.com.cn</a></p>
<script type="text/javascript">
x=document.getElementById("myAnchor");
document.write(x.type);
</script>
</body>
</html>
TIY
MIME
<html>
<body>
<p><a id="myAnchor" type="text/html"
href="http://www.w3school.com.cn">W3School.com.cn</a></p>
<script type="text/javascript">
x=document.getElementById("myAnchor");
document.write(x.type);
</script>
</body>
</html>
useMap usemap
imageObject.useMap=URL
usemap
<html>
<body>
<img id="planets" src="planets.gif"
width="145" height="126"
usemap="#planetmap" />
<map name="planetmap">
<area id="venus" shape="circle"
coords="124,58,8"
alt="The planet Venus"
href="venus.htm" />
</map>
<p>The value of the usemap attribute=
<script type="text/javascript">
x=document.getElementById('planets');
document.write(x.useMap);
</script>
</p>
</body>
</html>
TIY
usemap
<html>
<body>
<img id="planets"
src="/i/eg_planets.jpg"
usemap="#planetmap" />
<map name="planetmap">
<area
shape="circle"
coords="180,139,14"
href ="/example/html/venus.html"
target ="_blank"
alt="Venus" />
</map>
<p>usemap =
<script type="text/javascript">
x=document.getElementById('planets');
document.write(x.useMap);
</script>
</p>
</body>
</html>
value
buttonObject.value=value
<html>
<body>
<input type="button" id="button1" name="button1" value="Click Me!"
/>
<p>The text on the button is:
<script type="text/javascript">
x=document.getElementById('button1');
document.write(x.value);
</script></p>
</body>
</html>
TIY
<html>
<body>
<input type="button" id="button1"
name="button1" value="Click Me!" />
vspace
Thspace vspace align
imageObject.vspace=pixels
hspace vspace
<html>
<head>
<script type="text/javascript">
function setSpace()
{
document.getElementById("compman").hspace="50"
document.getElementById("compman").vspace="50"
}
</script>
</head>
<body>
<img id="compman" src="compman.gif" alt="Computerman" align="right"
/>
TIY
<html>
<head>
<script type="text/javascript">
function setSpace()
{
document.getElementById("compman").hspace="50"
document.getElementById("compman").vspace="50"
}
</script>
</head>
<body>
<img id="compman" src="/i/eg_compman.gif" alt="Computerman"
align="right" />
<p>Some text. Some text. Some text. Some text.</p>
<input type="button" onclick="setSpace()" value="Set hspace and
vspace">
</body>
</html>
width
imageObject.width=pixels
<html>
<head>
<script type="text/javascript">
function changeSize()
{
document.getElementById("compman").height="250"
document.getElementById("compman").width="300"
}
</script>
</head>
<body>
<img id="compman" src="compman.gif" width="107" height="98" />
<br /><br />
<input type="button" onclick="changeSize()"
value="Change size of image">
</body>
</html>
TIY
<html>
<head>
<script type="text/javascript">
function changeSize()
{
document.getElementById("compman").height="270"
document.getElementById("compman").width="164"
}
</script>
</head>
<body>
<img id="compman" src="/i/eg_bulbon.gif" />
<br /><br />
<input type="button" onclick="changeSize()" value="
">
</body>
</html>
className class
object.className=classname
<body> class
<html>
<body id="myid" class="mystyle">
<script type="text/javascript">
x=document.getElementsByTagName('body')[0];
document.write("Body CSS class: " + x.className);
document.write("<br />");
document.write("An alternate way: ");
document.write(document.getElementById('myid').className);
</script>
</body>
</html>
TIY
<body> class
<html>
<body id="myid" class="mystyle">
<script type="text/javascript">
x=document.getElementsByTagName('body')[0];
document.write("Body CSS class: " + x.className);
document.write("<br />");
document.write("An alternate way: ");
document.write(document.getElementById('myid').className);
</script>
</body>
</html>
dir
object.dir=text-direction
<body>
<html>
<body id="myid" dir="rtl">
<script type="text/javascript">
x=document.getElementsByTagName('body')[0];
document.write("Text direction: " + x.dir);
document.write("<br />");
document.write("An alternate way: ");
document.write(document.getElementById('myid').dir);
</script>
</body>
</html>
TIY
<body>
<html>
<body id="myid" dir="rtl">
<script type="text/javascript">
x=document.getElementsByTagName('body')[0];
document.write("Text direction: " + x.dir);
document.write("<br />");
document.write("An alternate way: ");
document.write(document.getElementById('myid').dir);
</script>
</body>
</html>
lang
object.lang=language-code
<body>
<html>
<body id="myid" lang="en-us">
<script type="text/javascript">
x=document.getElementsByTagName('body')[0];
document.write("Body language: " + x.lang);
document.write("<br />");
document.write("An alternate way: ");
document.write(document.getElementById('myid').lang);
</script>
</body>
</html>
TIY
<body>
<html>
<body id="myid" lang="en-us">
<script type="text/javascript">
x=document.getElementsByTagName('body')[0];
document.write("Body language: " + x.lang);
document.write("<br />");
document.write("An alternate way: ");
document.write(document.getElementById('myid').lang);
</script>
</body>
</html>
title
object.title=title
1
<body> title
<html>
<body id="myid" title="mytitle">
<script type="text/javascript">
x=document.getElementsByTagName('body')[0];
document.write("Body title: " + x.title);
document.write("<br />");
document.write("An alternate way: ");
document.write(document.getElementById('myid').title);
</script>
</body>
</html>
2
title
<html>
<body>
<img src ="planets.gif"
width="145" height="126"
alt="Planets"
usemap ="#planetmap" />
TIY
<body> title
<html>
<body id="myid" title="mytitle">
<script type="text/javascript">
x=document.getElementsByTagName('body')[0];
document.write("Body title: " + x.title);
document.write("<br />");
document.write("An alternate way: ");
document.write(document.getElementById('myid').title);
</script>
</body>
</html>
title
<html>
<body>
<img id="planets"
src="/i/eg_planets.jpg"
usemap="#planetmap" />
<map name="planetmap">
<area id="venus" shape="circle"
coords="180,139,14"
href ="/example/html/venus.html"
target ="_blank"
title="Venus" />
</map>
</map>
<p>Venus title
<script type="text/javascript">
x=document.getElementById('venus')
document.write(x.title)
</script>
</p>
</body>
</html>
blur()
anchorObject.blur()
<html>
<head>
<style type="text/css">
a:active {color:green}
</style>
<script type="text/javascript">
function getfocus()
{document.getElementById('myAnchor').focus()}
function losefocus()
{document.getElementById('myAnchor').blur()}
</script>
</head>
<body>
<a id="myAnchor"
href="http://www.w3school.com.cn">Visit W3School.com.cn</a>
<br /><br/>
<input type="button" onclick="getfocus()" value="Get focus">
<input type="button" onclick="losefocus()" value="Lose focus">
</body>
</html>
TIY
focus() blur()
<html>
<head>
<style type="text/css">
a:active {color:green}
</style>
<script type="text/javascript">
function getfocus()
{document.getElementById('myAnchor').focus()}
function losefocus()
{document.getElementById('myAnchor').blur()}
</script>
</head>
<body>
<a id="myAnchor" href="http://www.w3school.com.cn">
W3School.com.cn</a>
<br /><br/>
<input type="button" onclick="getfocus()" value="">
click()
buttonObject.click()
body onload
<html>
<head>
<script type="text/javascript">
function clickButton()
{
document.getElementById('button1').click()
}
function alertMsg()
{
alert("Button 1 was clicked!")
}
</script>
</head>
<body onload="clickButton()">
<form>
<input type="button" id="button1" onclick="alertMsg()"
value="Button 1" />
</form>
</body>
</html>
TIY
<html>
<head>
<script type="text/javascript">
function clickButton()
{
document.getElementById('button1').click()
}
function alertMsg()
{
alert("Button 1 was clicked!")
}
</script>
</head>
<body onload="clickButton()">
<form>
<input type="button" id="button1" onclick="alertMsg()" value="Button
1" />
</form>
</body>
</html>
focus()
buttonObject.focus()
<html>
<head>
<script type="text/javascript">
function setFocus()
{
document.getElementById('button1').focus()
}
</script>
</head>
<body>
<form>
<input type="button" id="button1" value="Button1" />
<br />
<input type="button" onclick="setFocus()"
value="Set focus to Button 1" />
</form>
</body>
</html>
TIY
<html>
<head>
<script type="text/javascript">
function setFocus()
{
document.getElementById('button1').focus()
}
function removeFocus()
{
document.getElementById('button1').blur()
}
</script>
</head>
<body>
<form>
<input type="button" id="button1" value="Button1" />
<br /><br />
<input type="button" onclick="setFocus()" value="Set focus" />
<input type="button" onclick="removeFocus()" value="Remove focus" />
</form>
</body>
</html>
reset()
formObject.reset()
Reset onreset
<html>
<head>
<script type="text/javascript">
function formReset()
{
document.getElementById("myForm").reset()
}
</script>
</head>
<form id="myForm">
TIY
<html>
<head>
<script type="text/javascript">
function formReset()
{
document.getElementById("myForm").reset()
}
</script>
</head>
<body>
<p></p>
<form id="myForm">
<input type="text" size="20"><br />
<input type="text" size="20"><br />
<br />
<input type="button" onclick="formReset()" value="">
</form>
</body>
</html>
submit() Web
formObject.submit()
Submit onsubmit
<html>
<head>
<script type="text/javascript">
function formSubmit()
{
document.getElementById("myForm").submit()
}
</script>
</head>
<body>
<form id="myForm" action="js_form_action.asp" method="get">
Firstname: <input type="text" name="firstname" size="20"><br />
Lastname: <input type="text" name="lastname" size="20"><br />
<br />
<input type="button" onclick="formSubmit()" value="Submit">
</form>
</body>
</html>
TIY
<html>
<head>
<script type="text/javascript">
function formSubmit()
{
document.getElementById("myForm").submit()
}
</script>
</head>
<body>
<p></p>
<form id="myForm" action="/i/eg_smile.gif" method="get">
<input type="text" name="firstname" size="20"><br />
<input type="text" name="lastname" size="20"><br />
<br />
<input type="button" onclick="formSubmit()" value="">
</form>
</body>
</html>
<html>
<head>
<script type="text/javascript">
function whichButton(event)
{
var btnNum = event.button;
if (btnNum==2)
{
alert("")
}
else if(btnNum==0)
{
alert("")
}
else if(btnNum==1)
{
alert("");
}
else
{
alert("" + btnNum+ "");
}
}
</script>
</head>
<body onmousedown="whichButton(event)">
<p></p>
</body>
</html>
<html>
<head>
<script type="text/javascript">
function show_coords(event)
{
x=event.clientX
y=event.clientY
alert("X : " + x + ", Y : " + y)
}
</script>
</head>
<body onmousedown="show_coords(event)">
<p> x y </p>
</body>
</html>
unicode
<html>
<head>
<script type="text/javascript">
function whichButton(event)
{
alert(event.keyCode)
}
</script>
</head>
<body onkeyup="whichButton(event)">
<p><b></b></p>
<p> unicode</p>
</body>
</html>
<html>
<head>
<script type="text/javascript">
function coordinates(event)
{
x=event.screenX
y=event.screenY
alert("X=" + x + " Y=" + y)
}
</script>
</head>
<body onmousedown="coordinates(event)">
<p>
x y
</p>
</body>
</html>
shift
<html>
<head>
<script type="text/javascript">
function isKeyPressed(event)
{
if (event.shiftKey==1)
{
alert("The shift key was pressed!")
}
else
{
alert("The shift key was NOT pressed!")
}
}
</script>
</head>
<body onmousedown="isKeyPressed(event)">
<p> shift </p>
</body>
</html>
<html>
<head>
<script type="text/javascript">
function whichElement(e)
{
var targ
if (!e) var e = window.event
if (e.target) targ = e.target
else if (e.srcElement) targ = e.srcElement
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode
var tname
tname=targ.tagName
alert("You clicked on a " + tname + " element.")
}
</script>
</head>
<body onmousedown="whichElement(event)">
<p></p>
<h3></h3>
<p></p>
<img src="/i/eg_mouse2.jpg" />
</body>
</html>
<html>
<head>
<script type="text/javascript">
function getEventType(event)
{
alert(event.type);
}
</script>
</head>
<body onmousedown="getEventType(event)">
<p></p>
</body>
</html>
Event
Event
(Event Handlers)
HTML 4.0 HTML
...
IE
W3C
onabort
Yes
onblur
Yes
onchange
Yes
onclick
Yes
ondblclick
Yes
onerror
Yes
onfocus
Yes
onkeydown
No
Yes
onkeypress
Yes
onkeyup
Yes
onload
Yes
onmousedown
Yes
onmousemove
Yes
onmouseout
Yes
onmouseover
Yes
onmouseup
Yes
onreset
Yes
onresize
Yes
onselect
Yes
onsubmit
Yes
onunload
Yes
IE
W3C
altKey
"ALT"
Yes
button
Yes
clientX
Yes
clientY
Yes
ctrlKey
"CTRL"
Yes
metaKey
"meta"
No
Yes
relatedTarget
No
Yes
screenX
Yes
screenY
Yes
shiftKey
"SHIFT"
Yes
IE
/IE
cancelBubble
true
fromElement
keyCode
keypress Unicode
keydown keyup
offsetX,offsetY
x y
returnValue
fasle
srcElement
toElement
mouseover mouseout
x,y
x y CSS
Event
2 DOM
IE
W3C
bubbles
No
Yes
cancelable
No
Yes
currentTarget
No
Yes
eventPhase
target
No
Yes
timeStamp
No
Yes
type
Event
Yes
Yes
Event
2 DOM IE
IE
W3C
initEvent()
Event
No
Yes
preventDefault()
No
Yes
stopPropagation()
No
Yes
onabort
onabort
stop
onabort="SomeJavaScriptCode"
SomeJavaScriptCode
JavaScript
HTML
<img>
JavaScript
image
<img src="image_w3default.gif"
onabort="alert('Error: Loading of the image was aborted')" />
<html>
<head>
<script type="text/javascript">
function abortImage()
{
alert('Error: Loading of the image was aborted')
}
</script>
</head>
<body>
<img src="image_w3default.gif" onabort="abortImage()" />
</body>
</html>
onblur
onblur
onblur="SomeJavaScriptCode"
SomeJavaScriptCode
JavaScript
HTML
<a>, <acronym>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>,
<button>, <caption>, <cite>, <dd>, <del>, <dfn>, <div>, <dl>, <dt>,
<em>, <fieldset>, <form>, <frame>, <frameset>, <h1> to <h6>, <hr>,
<i>, <iframe>, <img>, <input>, <ins>, <kbd>, <label>, <legend>, <li>,
<object>, <ol>, <p>, <pre>, <q>, <samp>, <select>, <small>, <span>,
<strong>, <sub>, <sup>, <table>, <tbody>, <td>, <textarea>, <tfoot>,
<th>, <thead>, <tr>, <tt>, <ul>, <var>
JavaScript
button, checkbox, fileUpload, layer, frame, password,
radio, reset, submit, text, textarea, window
1
JavaScript
<html>
<head>
<script type="text/javascript">
function upperCase()
{
var x=document.getElementById("fname").value
document.getElementById("fname").value=x.toUpperCase()
}
</script>
</head>
<body>
TIY
onblur
onblur JavaScript
<html>
<head>
<script type="text/javascript">
function upperCase()
{
var x=document.getElementById("fname").value
document.getElementById("fname").value=x.toUpperCase()
}
</script>
</head>
<body>
Enter your name: <input type="text" id="fname"
onblur="upperCase()"><br />
Enter your age: <input type="text" id="age" onblur="alert(this.id)">
</body>
</html>
onchange
onchange
onchange="SomeJavaScriptCode"
SomeJavaScriptCode
JavaScript
HTML
<input type="text">, <select>, <textarea>
JavaScript
fileUpload, select, text, textarea
1
JavaScript
<html>
<head>
<script type="text/javascript">
function upperCase(x)
{
var y=document.getElementById(x).value
document.getElementById(x).value=y.toUpperCase()
}
</script>
</head>
<body>
<input type="text" id="fname" onchange="upperCase(this.id)" />
</body>
</html>
TIY
onchange
onchange JavaScript
<html>
<head>
<script type="text/javascript">
function upperCase(x)
{
var y=document.getElementById(x).value
document.getElementById(x).value=y.toUpperCase()
}
</script>
</head>
<body>
Enter your name: <input type="text" id="fname"
onchange="upperCase(this.id)">
</body>
</html>
onclick
onclick
onclick onmousedown
onclick="SomeJavaScriptCode"
SomeJavaScriptCode
JavaScript
HTML
<a>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <body>,
<button>, <caption>, <cite>, <code>, <dd>, <dfn>, <div>, <dl>, <dt>,
<em>, <fieldset>, <form>, <h1> to <h6>, <hr>, <i>, <img>, <input>,
<kbd>, <label>, <legend>, <li>, <map>, <object>, <ol>, <p>, <pre>,
<samp>, <select>, <small>, <span>, <strong>, <sub>, <sup>, <table>,
<tbody>, <td>, <textarea>, <tfoot>, <th>, <thead>, <tr>, <tt>, <ul>,
<var>
JavaScript
button, document, checkbox, link, radio, reset, submit
<html>
<body>
Field1: <input type="text" id="field1" value="Hello World!">
<br />
Field2: <input type="text" id="field2">
<br /><br />
Field1 Field2
<br />
<button onclick="document.getElementById('field2').value=
document.getElementById('field1').value">Copy Text</button>
</body>
</html>
TIY
onclick
onclick
<html>
<body>
Field1: <input type="text" id="field1" value="Hello World!">
<br />
Field2: <input type="text" id="field2">
<br /><br />
Click the button below to copy the content of Field1 to Field2.
<br />
<button onclick="document.getElementById('field2').value=
document.getElementById('field1').value">Copy Text</button>
</body>
</html>
ondblclick
ondblclick
ondblclick="SomeJavaScriptCode"
SomeJavaScriptCode
JavaScript
HTML
<a>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <body>,
JavaScript
document, link
<html>
<body>
Field1: <input type="text" id="field1" value="Hello World!">
<br />
Field2: <input type="text" id="field2">
<br /><br />
Field1 Field2
<br />
<button ondblclick="document.getElementById('field2').value=
document.getElementById('field1').value">Copy Text</button>
</body>
</html>
TIY
ondblclick
ondblclick
<html>
<body>
Field1: <input type="text" id="field1" value="Hello World!">
<br />
Field2: <input type="text" id="field2">
onerror
onerror
onerror="SomeJavaScriptCode"
SomeJavaScriptCode
JavaScript
HTML
<img>, <object>, <style>
JavaScript
window, image
loaded.')" />
TIY
onerror
onerror
<html>
<body>
<img src="image.gif"
onerror="alert('The image could not be loaded.')">
<p></p>
</body>
</html>
onfocus
onfocus
onfocus="SomeJavaScriptCode"
SomeJavaScriptCode
JavaScript
HTML
<a>, <acronym>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>,
<button>, <caption>, <cite>, <dd>, <del>, <dfn>, <div>, <dl>, <dt>,
<em>, <fieldset>, <form>, <frame>, <frameset>, <h1> to <h6>, <hr>,
<i>, <iframe>, <img>, <input>, <ins>, <kbd>, <label>, <legend>, <li>,
JavaScript
button, checkbox, fileUpload, layer, frame, password, radio, reset,
select, submit, text, textarea, window
<html>
<head>
<script type="text/javascript">
function setStyle(x)
{
document.getElementById(x).style.background="yellow"
}
</script>
</head>
<body>
First name: <input type="text"
onfocus="setStyle(this.id)" id="fname" />
<br />
Last name: <input type="text"
onfocus="setStyle(this.id)" id="lname" />
</body>
</html>
TIY
onfocus
onfocus
<html>
<head>
<script type="text/javascript">
function setStyle(x)
{
document.getElementById(x).style.background="yellow"
}
</script>
</head>
<body>
First name: <input type="text" onfocus="setStyle(this.id)"
id="fname">
<br />
Last name: <input type="text" onfocus="setStyle(this.id)"
id="lname">
</body>
</html>
onkeydown
onkeydown
onkeydown="SomeJavaScriptCode"
SomeJavaScriptCode
JavaScript
HTML
<a>, <acronym>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>,
<body>, <button>, <caption>, <cite>, <code>, <dd>, <del>, <dfn>, <div>,
<dt>, <em>, <fieldset>, <form>, <h1> to <h6>, <hr>, <i>, <input>, <kbd>,
<label>, <legend>, <li>, <map>, <object>, <ol>, <p>, <pre>, <q>, <samp>,
<select>, <small>, <span>, <strong>, <sub>, <sup>, <table>, <tbody>,
JavaScript
document, image, link, textarea
Internet Explorer
Netscape/Firefox/Opera event.which
event.keyCode
<html>
<body>
<script type="text/javascript">
function noNumbers(e)
{
var keynum
var keychar
var numcheck
if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
keychar = String.fromCharCode(keynum)
numcheck = /\d/
return !numcheck.test(keychar)
}
</script>
<form>
<input type="text" onkeydown="return noNumbers(event)" />
</form>
</html>
rTIY
onkeydown
onkeydown
<html>
<body>
<script type="text/javascript">
function noNumbers(e)
{
var keynum
var keychar
var numcheck
if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
keychar = String.fromCharCode(keynum)
numcheck = /\d/
return !numcheck.test(keychar)
}
</script>
<form>
Type some text (numbers not allowed):
<input type="text" onkeydown="return noNumbers(event)" />
</form>
</html>
onkeypress
onkeypress
onkeypress="SomeJavaScriptCode"
SomeJavaScriptCode
JavaScript
HTML
<a>, <acronym>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>,
<body>, <button>, <caption>, <cite>, <code>, <dd>, <del>, <dfn>, <div>,
<dt>, <em>, <fieldset>, <form>, <h1> to <h6>, <hr>, <i>, <input>, <kbd>,
<label>, <legend>, <li>, <map>, <object>, <ol>, <p>, <pre>, <q>, <samp>,
<select>, <small>, <span>, <strong>, <sub>, <sup>, <table>, <tbody>,
<td>, <textarea>, <tfoot>, <th>, <thead>, <tr>, <tt>, <ul>, <var>
JavaScript
document, image, link, textarea
Internet Explorer
Netscape/Firefox/Opera event.which
<html>
event.keyCode
<body>
<script type="text/javascript">
function noNumbers(e)
{
var keynum
var keychar
var numcheck
if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
keychar = String.fromCharCode(keynum)
numcheck = /\d/
return !numcheck.test(keychar)
}
</script>
<form>
<input type="text" onkeypress="return noNumbers(event)" />
</form>
</html>
TIY
onkeypress
onkeypress
<html>
<body>
<script type="text/javascript">
function noNumbers(e)
{
var keynum
var keychar
var numcheck
if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
keychar = String.fromCharCode(keynum)
numcheck = /\d/
return !numcheck.test(keychar)
}
</script>
<form>
Type some text (numbers not allowed):
<input type="text" onkeypress="return noNumbers(event)" />
</form>
</html>
onKeyUp
onkeyup
onkeyup="SomeJavaScriptCode"
SomeJavaScriptCode
JavaScript
HTML
<a>, <acronym>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>,
<body>, <button>, <caption>, <cite>, <code>, <dd>, <del>, <dfn>, <div>,
<dt>, <em>, <fieldset>, <form>, <h1> to <h6>, <hr>, <i>, <input>, <kbd>,
<label>, <legend>, <li>, <map>, <object>, <ol>, <p>, <pre>, <q>, <samp>,
<select>, <small>, <span>, <strong>, <sub>, <sup>, <table>, <tbody>,
<td>, <textarea>, <tfoot>, <th>, <thead>, <tr>, <tt>, <ul>, <var>
JavaScript
document, image, link, textarea
<html>
<head>
<script type="text/javascript">
function upperCase(x)
{
var y=document.getElementById(x).value
document.getElementById(x).value=y.toUpperCase()
}
</script>
</head>
<body>
<input type="text" id="fname"
onkeyup="upperCase(this.id)" />
</body>
</html>
TIY
onkeyup
onkeyup
<html>
<head>
<script type="text/javascript">
function upperCase(x)
{
var y=document.getElementById(x).value
document.getElementById(x).value=y.toUpperCase()
}
</script>
</head>
<body>
Enter your name: <input type="text" id="fname"
onkeyup="upperCase(this.id)">
</body>
</html>
onload
onload
onload="SomeJavaScriptCode"
SomeJavaScriptCode
JavaScript
HTML
<body>, <frame>, <frameset>, <iframe>, <img>, <link>, <script>
JavaScript
image, layer, window
"Page is loaded"
<html>
<head>
<script type="text/javascript">
function load()
{
window.status="Page is loaded"
}
</script>
</head>
<body onload="load()">
</body>
</html>
TIY
onload
onload
<html>
<head>
<script type="text/javascript">
function load()
{
window.status="Page is loaded"
}
</script>
</head>
<body onload="load()">
</body>
</html>
onmousedown
onmousedown
onmousedown="SomeJavaScriptCode"
SomeJavaScriptCode
JavaScript
HTML
<a>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <body>,
<button>, <caption>, <cite>, <code>, <dd>, <dfn>, <div>, <dl>, <dt>,
<em>, <fieldset>, <form>, <h1> to <h6>, <hr>, <i>, <img>, <input>,
<kbd>, <label>, <legend>, <li>, <map>, <ol>, <p>, <pre>, <samp>,
<select>, <small>, <span>, <strong>, <sub>, <sup>, <table>, <tbody>,
<td>, <textarea>, <tfoot>, <th>, <thead>, <tr>, <tt>, <ul>, <var>
JavaScript
button, document, link
<img src="/i/example_mouse2.jpg"
onmousedown="alert('You clicked the picture!')" />
<html>
<head>
<script type="text/javascript">
function whichElement(e)
{
var targ
if (!e) var e = window.event
if (e.target) targ = e.target
else if (e.srcElement) targ = e.srcElement
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode
var tname
tname=targ.tagName
alert("You clicked on a " + tname + " element.")
}
</script>
</head>
<body onmousedown="whichElement(event)">
<h2>This is a header</h2>
<p>This is a paragraph</p>
<img border="0" src="ball16.gif" alt="Ball">
</body>
</html>
TIY
onmousedown
onmousedown
<html>
<body>
<img src="/i/eg_mouse2.jpg" onMouseDown="alert('You clicked the
picture!')">
<p>Click the picture</p>
</body>
</html>
onmousedown 2
onmousedown
<html>
<head>
<script type="text/javascript">
function whichElement(e)
{
var targ
if (!e) var e = window.event
if (e.target) targ = e.target
else if (e.srcElement) targ = e.srcElement
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode
var tname
tname=targ.tagName
alert("You clicked on a " + tname + " element.")
}
</script>
</head>
<body onmousedown="whichElement(event)">
<p></p>
<h3></h3>
<p></p>
<img src="/i/eg_mouse2.jpg" />
</body>
</html>
onmousemove
onmousemove
onmousemove="SomeJavaScriptCode"
SomeJavaScriptCode
JavaScript
HTML
<a>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <body>,
<button>, <caption>, <cite>, <code>, <dd>, <dfn>, <div>, <dl>, <dt>,
<em>, <fieldset>, <form>, <h1> to <h6>, <hr>, <i>, <img>, <input>,
<kbd>, <label>, <legend>, <li>, <map>, <ol>, <p>, <pre>, <samp>,
<select>, <small>, <span>, <strong>, <sub>, <sup>, <table>, <tbody>,
<td>, <textarea>, <tfoot>, <th>, <thead>, <tr>, <tt>, <ul>, <var>
JavaScript
onmousemove is, by default, not an event of any object,
because mouse movement happens very frequently.
mousemove
mousemove
TIY
onmousemove
onmousemove
<html>
<body>
<img src="/i/eg_mouse2.jpg" name="mousetest">
<p onmousemove="document.images['mousetest']
.src='/i/eg_mouse.jpg'">When you move the mouse pointer over this
paragraph, the image changes.</p>
</body>
</html>
onmouseout
onmouseout
onmouseout="SomeJavaScriptCode"
SomeJavaScriptCode
JavaScript
HTML
<a>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <body>,
<button>, <caption>, <cite>, <code>, <dd>, <dfn>, <div>, <dl>, <dt>,
<em>, <fieldset>, <form>, <h1> to <h6>, <hr>, <i>, <img>, <input>,
<kbd>, <label>, <legend>, <li>, <map>, <ol>, <p>, <pre>, <samp>,
<select>, <small>, <span>, <strong>, <sub>, <sup>, <table>, <tbody>,
<td>, <textarea>, <tfoot>, <th>, <thead>, <tr>, <tt>, <ul>, <var>
JavaScript
layer, link
<html>
<head>
<script type="text/javascript">
function mouseOver()
{
document.getElementById('b1').src ="/i/eg_mouse.jpg"
}
function mouseOut()
{
document.getElementById('b1').src ="/i/eg_mouse2.jpg"
}
</script>
</head>
<body>
<a href="http://www.w3school.com.cn"
onmouseover="mouseOver()" onmouseout="mouseOut()">
<img alt="Visit W3School!" src="/i/example_mouse2.jpg" id="b1" />
</a>
</body>
</html>
TIY
onmouseout
onmouseout
<html>
<head>
<script type="text/javascript">
function mouseOver()
{
document.getElementById('b1').src ="/i/eg_mouse.jpg"
}
function mouseOut()
{
document.getElementById('b1').src ="/i/eg_mouse2.jpg"
}
</script>
</head>
<body>
<a href="http://www.w3school.com.cn" onmouseover="mouseOver()"
onmouseout="mouseOut()">
<img alt="Visit W3School!" src="/i/eg_mouse2.jpg" id="b1" />
</a>
</body>
</html>
onmouseover
onmouseover
onmouseover="SomeJavaScriptCode"
SomeJavaScriptCode
JavaScript
HTML
<a>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <body>,
<button>, <caption>, <cite>, <code>, <dd>, <dfn>, <div>, <dl>, <dt>,
<em>, <fieldset>, <form>, <h1> to <h6>, <hr>, <i>, <img>, <input>,
<kbd>, <label>, <legend>, <li>, <map>, <ol>, <p>, <pre>, <samp>,
<select>, <small>, <span>, <strong>, <sub>, <sup>, <table>, <tbody>,
<td>, <textarea>, <tfoot>, <th>, <thead>, <tr>, <tt>, <ul>, <var>
JavaScript
layer, link
<html>
<head>
<script type="text/javascript">
function mouseOver()
{
document.getElementById('b1').src ="/i/eg_mouse.jpg"
}
function mouseOut()
{
document.getElementById('b1').src ="/i/eg_mouse2.jpg"
}
</script>
</head>
<body>
<a href="http://www.w3school.com.cn"
onmouseover="mouseOver()" onmouseout="mouseOut()">
<img alt="Visit W3School!" src="/i/eg_mouse2.jpg" id="b1" />
</a>
</body>
</html>
TIY
onmouseover
onmouseover
<html>
<head>
<script type="text/javascript">
function mouseOver()
{
document.getElementById('b1').src ="/i/eg_mouse.jpg"
}
function mouseOut()
{
document.getElementById('b1').src ="/i/eg_mouse2.jpg"
}
</script>
</head>
<body>
<a href="http://www.w3school.com.cn" onmouseover="mouseOver()"
onmouseout="mouseOut()">
<img alt="Visit W3School!" src="/i/eg_mouse2.jpg" id="b1" />
</a>
</body>
</html>
onreset
onreset
onreset="SomeJavaScriptCode"
SomeJavaScriptCode
JavaScript
HTML
<form>
JavaScript
form
TIY
onreset
onreset reset
<html>
<body>
<form onreset="alert('The form will be reset')">
Firstname: <input type="text" name="fname" value="John" />
<br />
Lastname: <input type="text" name="lname" />
<br /><br />
<input type="reset" value="Reset">
</form>
</body>
</html>
onresize
onresize
onresize="SomeJavaScriptCode"
SomeJavaScriptCode
JavaScript
HTML
<a>, <address>, <b>, <big>, <blockquote>, <body>, <button>, <cite>,
<code>, <dd>, <dfn>, <div>, <dl>, <dt>, <em>, <fieldset>, <form>,
JavaScript
window
TIY
onresize
onresize
<html>
<body onresize="alert('You have changed the size of the window')">
<p>Try to resize the browser window.</p>
</body>
</html>
onselect
onselect
onselect="SomeJavaScriptCode"
SomeJavaScriptCode
JavaScript
HTML
<input type="text">, <textarea>
JavaScript
window
<form>
Select text: <input type="text" value="Hello world!"
onselect="alert('You have selected some of the text.')" />
<br /><br />
Select text: <textarea cols="20" rows="5"
onselect="alert('You have selected some of the text.')">
Hello world!</textarea>
</form>
TIY
onselect
onselect
<form>
Select text: <input type="text" value="Hello world!"
onselect="alert('You have selected some of the text.')">
<br /><br />
Select text: <textarea cols="20" rows="5"
onselect="alert('You have selected some of the text.')">
Hello world!
onsubmit
onsubmit
onsubmit="SomeJavaScriptCode"
SomeJavaScriptCode
JavaScript
HTML
<form>
JavaScript
form
TIY
onsubmit
onsubmit
<html>
<body>
<h1>What is your name?</h1>
<form name="testform" action="/example/hdom/hdom_onsubmit.html"
onSubmit="alert('Hello ' + testform.inputfield.value +'!')">
<input type="text" name="inputfield" size="20">
<input type="submit" value="Submit">
</form>
</body>
</html>
onunload
onunload
onunload="SomeJavaScriptCode"
SomeJavaScriptCode
JavaScript
HTML
<body>, <frameset>
JavaScript
window
TIY
onunload
onunload
<html>
<body onunload="alert('The onunload event was triggered')">
<p>Close the page to trigger the onunload event.</p>
</body>
</html>
altKey
altKey Alt
event.altKey=true|false|1|0
"ALT"
<html>
<head>
<script type="text/javascript">
function isKeyPressed(event)
{
if (event.altKey==1)
{
alert("The ALT key was pressed!")
}
else
{
alert("The ALT key was NOT pressed!")
}
}
</script>
</head>
<body onmousedown="isKeyPressed(event)">
<p>Click somewhere in the document.
An alert box will tell you if you
pressed the ALT key or not.</p>
</body>
</html>
TIY
altKey
ALT
<html>
<head>
<script type="text/javascript">
function isKeyPressed(event)
{
if (event.altKey==1)
{
button
button
event.button=0|1|2
Internet Explorer
Mozilla CtrlClick 2
TIY
button
<html>
<head>
<script type="text/javascript">
function whichButton(event)
{
var btnNum = event.button;
if (btnNum==2)
{
alert("")
}
else if(btnNum==0)
{
alert("")
}
else if(btnNum==1)
{
alert("");
}
else
{
alert("" + btnNum+ "");
}
}
</script>
</head>
<body onmousedown="whichButton(event)">
<p></p>
</body>
</html>
clientX
clientX
event.clientX
2 DOM IE
window.pageXOffset window.pageYOffset
<html>
<head>
<script type="text/javascript">
function show_coords(event)
{
x=event.clientX
y=event.clientY
alert("X coords: " + x + ", Y coords: " + y)
}
</script>
</head>
<body onmousedown="show_coords(event)">
<p>Click in the document. An alert box will alert
the x and y coordinates of the mouse pointer.</p>
</body>
</html>
TIY
clientX
<html>
<head>
<script type="text/javascript">
function show_coords(event)
{
x=event.clientX
y=event.clientY
alert("X : " + x + ", Y : " + y)
}
</script>
</head>
<body onmousedown="show_coords(event)">
<p> x y </p>
</body>
</html>
clientY
clientY
event.clientY
clientY 02 DOM
IE window.pageXOffset window.pageYOffset
<html>
<head>
<script type="text/javascript">
function show_coords(event)
{
x=event.clientX
y=event.clientY
alert("X coords: " + x + ", Y coords: " + y)
}
</script>
</head>
<body onmousedown="show_coords(event)">
<p>Click in the document. An alert box will alert
the x and y coordinates of the mouse pointer.</p>
</body>
</html>
TIY
clientY
<html>
<head>
<script type="text/javascript">
function show_coords(event)
{
x=event.clientX
y=event.clientY
alert("X : " + x + ", Y : " + y)
}
</script>
</head>
<body onmousedown="show_coords(event)">
<p> x y </p>
</body>
</html>
ctrlKey
ctrlKey Ctrl
event.ctrlKey=true|false|1|0
"CTRL"
<html>
<head>
<script type="text/javascript">
function isKeyPressed(event)
{
if (event.ctrlKey==1)
{
alert("The CTRL key was pressed!")
}
else
{
alert("The CTRL key was NOT pressed!")
}
}
</script>
</head>
<body onmousedown="isKeyPressed(event)">
<p>Click somewhere in the document.
An alert box will tell you if you
pressed the CTRL key or not.</p>
</body>
</html>
TIY
ctrlKey
CTRL
<html>
<head>
<script type="text/javascript">
function isKeyPressed(event)
{
if (event.ctrlKey==1)
{
alert("The CTRL key was pressed!")
}
else
{
alert("The CTRL key was NOT pressed!")
}
}
</script>
</head>
<body onmousedown="isKeyPressed(event)">
<p>Click somewhere in the document. An alert box will tell you if you
pressed the CTRL key or not.</p>
</body>
</html>
metaKey
metaKey "meta"
event.metaKey
"meta"
<html>
<head>
<script type="text/javascript">
function isKeyPressed(event)
{
if (event.metaKey==1)
{
alert("The meta key was pressed!")
}
else
{
alert("The meta key was NOT pressed!")
}
}
</script>
</head>
<body onmousedown="isKeyPressed(event)">
<p>Click somewhere in the document.
An alert box will tell you if you
pressed the meta key or not.</p>
</body>
</html>
TIY
metakey
meta IE
<html>
<head>
<script type="text/javascript">
function isKeyPressed(event)
{
if (event.metaKey==1)
{
alert("The meta key was pressed!")
}
else
{
alert("The meta key was NOT pressed!")
}
}
</script>
</head>
<body onmousedown="isKeyPressed(event)">
<p>Click somewhere in the document. An alert box will tell you if you
pressed the meta key or not.</p>
</body>
</html>
relatedTarget
relatedTarget
mouseover
mouseout
event.relatedTarget
<html>
<head>
<script type="text/javascript">
function getRelElement(event)
{
var txt="The cursor just exited the ";
txt=txt + event.relatedTarget.tagName + " element.";
alert(txt);
}
</script>
</head>
<body>
<p onmouseover="getRelElement(event)">
Mouse over this paragraph.</p>
</body>
</html>
TIY
relatedtarget
IE
<html>
<head>
<script type="text/javascript">
function getRelatedElement(event)
{
alert("The cursor just exited the " + event.relatedTarget.tagName
+ " element.");
}
</script>
</head>
<body>
<p onmouseover="getRelatedElement(event)">Mouse over this
paragraph.</p>
</body>
</html>
screenX
screenX
event.screenX
<html>
<head>
<script type="text/javascript">
function show_coords(event)
{
x=event.screenX
y=event.screenY
alert("X coords: " + x + ", Y coords: " + y)
}
</script>
</head>
<body onmousedown="show_coords(event)">
<p>Click in the document. An alert box will alert
the x and y coordinates of the cursor.</p>
</body>
</html>
TIY
screenX
<html>
<head>
<script type="text/javascript">
function coordinates(event)
{
x=event.screenX
y=event.screenY
alert("X=" + x + " Y=" + y)
}
</script>
</head>
<body onmousedown="coordinates(event)">
<p>
x y
</p>
</body>
</html>
screenY
screenY
event.screenY
<html>
<head>
<script type="text/javascript">
function show_coords(event)
{
x=event.screenX
y=event.screenY
alert("X coords: " + x + ", Y coords: " + y)
}
</script>
</head>
<body onmousedown="show_coords(event)">
<p>Click in the document. An alert box will alert
the x and y coordinates of the cursor.</p>
</body>
</html>
TIY
screenY
<html>
<head>
<script type="text/javascript">
function coordinates(event)
{
x=event.screenX
y=event.screenY
alert("X=" + x + " Y=" + y)
}
</script>
</head>
<body onmousedown="coordinates(event)">
<p>
x y
</p>
</body>
</html>
shiftKey
shiftKey "SHIFT"
event.shiftKey=true|false|1|0
"SHIFT"
<html>
<head>
<script type="text/javascript">
function isKeyPressed(event)
{
if (event.shiftKey==1)
{
alert("The shift key was pressed!")
}
else
{
alert("The shift key was NOT pressed!")
}
}
</script>
</head>
<body onmousedown="isKeyPressed(event)">
<p>Click somewhere in the document.
An alert box will tell you if you
pressed the shift key or not.</p>
</body>
</html>
TIY
shiftKey
SHIFT
<html>
<head>
<script type="text/javascript">
function isKeyPressed(event)
{
if (event.shiftKey==1)
{
alert("The shift key was pressed!")
}
else
{
alert("The shift key was NOT pressed!")
}
}
</script>
</head>
<body onmousedown="isKeyPressed(event)">
<p> shift </p>
</body>
</html>
bubbles
event.bubbles
2 DOM
Document
Document
<html>
<head>
<script type="text/javascript">
function getEventType(event)
{
alert(event.bubbles);
}
</script>
</head>
<body onmousedown="getEventType(event)">
<p>Click somewhere in the document.
An alert box will tell if the event is a bubbling event.</p>
</body>
</html>
TIY
bubbling event
IE
<html>
<head>
<script type="text/javascript">
function getEventType(event)
{
alert(event.bubbles);
}
</script>
</head>
<body onmousedown="getEventType(event)">
<p>Click somewhere in the document. An alert box will tell if the event
is a bubbling event.</p>
</body>
</html>
cancelable
cancelable preventDefault()
true fasle
event.cancelable
cancelable
<html>
<head>
<script type="text/javascript">
function isEventCancelable(event)
{
alert(event.cancelable);
}
</script>
</head>
<body onmousedown="isEventCancelable(event)">
<p>Click somewhere in the document.
An alert box will tell if the
event is a cancelable event.</p>
</body>
</html>
TIY
cancelable event
cancelable IE
<html>
<head>
<script type="text/javascript">
function isEventCancelable(event)
{
alert(event.cancelable);
}
</script>
</head>
<body onmousedown="isEventCancelable(event)">
<p>Click somewhere in the document. An alert box will tell if the event
is a cancelable event.</p>
</body>
</html>
currentTarget
currentTarget
target
event.currentTarget
<html>
<head>
<script type="text/javascript">
function getEventTrigger(event)
{
x=event.currentTarget;
alert("The id of the triggered element: "
+ x.id);
}
</script>
</head>
<body >
<p id="p1" onmousedown="getEventTrigger(event)">
Click on this paragraph. An alert box will
show which element triggered the event.</p>
</body>
</html>
TIY
currenttarget event
<html>
<head>
<script type="text/javascript">
function getEventTrigger(event)
{
x=event.currentTarget;
alert("The id of the triggered element: "
+ x.id);
}
</script>
</head>
<body >
<p id="p1" onmousedown="getEventTrigger(event)">
Click on this paragraph. An alert box will
show which element triggered the event.</p>
</body>
</html>
eventPhase
eventPhase
eventPhase
Event.CAPTURING_PHASE
Event.AT_TARGET
Event.BUBBLING_PHASE
target
target
event.target
<html>
<head>
<script type="text/javascript">
function getEventTrigger(event)
{
x=event.target;
alert("The id of the triggered element: "
+ x.id);
}
</script>
</head>
<body >
<p id="p1" onmousedown="getEventTrigger(event)">
Click on this paragraph. An alert box will
show which element triggered the event.</p>
</body>
</html>
TIY
target event
IE
<html>
<head>
<script type="text/javascript">
function getEventTrigger(event)
{
x=event.target;
alert("The id of the triggered element: " + x.id);
}
</script>
</head>
<body >
<p id="p1" onmousedown="getEventTrigger(event)">
Click on this paragraph. An alert box will show which element triggered
the event.</p>
</body>
</html>
timeStamp
timeStamp epoch
epoch
timeStamp /
event.timeStamp
<html>
<head>
<script type="text/javascript">
function showTimestamp(event)
{
var minutes = 1000*60
x=event.timeStamp;
alert(x/minutes)
}
</script>
</head>
<body onmousedown="showTimestamp(event)">
<p>Click in the document. An alert
box will alert the timestamp.</p>
</body>
</html>
TIY
timestamp event
IE
<html>
<head>
<script type="text/javascript">
function showTimestamp(event)
{
var minutes = 1000*60
x=event.timeStamp;
alert(x/minutes)
}
</script>
</head>
<body onmousedown="showTimestamp(event)">
<p>Click in the document. An alert box will alert the timestamp.</p>
</body>
</html>
type
type Event
"on" "submit""load"
"click"
event.type
<html>
<head>
<script type="text/javascript">
function getEventType(event)
{
alert(event.type);
}
</script>
</head>
<body onmousedown="getEventType(event)">
TIY
type event
IE
<html>
<head>
<script type="text/javascript">
function getEventType(event)
{
alert(event.type);
}
</script>
</head>
<body onmousedown="getEventType(event)">
<p></p>
</body>
</html>
initEvent()
event.initEvent(eventType,canBubble,cancelable)
eventType
canBubble
cancelable
preventDefault()
preventDefault()
event.preventDefault()
Web
type "submit"
Event cancelable fasle
stopPropagation()
event.stopPropagation()
Document
Document
W3School
W3School