37-Javascript-Window and Document Object-04-02-2023
37-Javascript-Window and Document Object-04-02-2023
In Statement
The code in the body of the for...in loop is executed once for each
property.
for (variable in object)
{
code to be executed
}
var person={fname:"John",lname:"Doe",age:25}; //object creation
var x;
for (x in person)
{
document.write(person[x] + " "); // John Doe 25
}
46 R.Vijayan/ AP(SG) / SITE / VIT University 4 February 2023
Date object
new Date( )
new Date(milliseconds)
new Date(datestring)
var dt = new Date("December 25, 1995 23:15:00");
new Date(year,month,date,hour,minute,second,millisecond )
button checkbox
radio select
reset textarea
text submit
setInterval(expre,time)
confirm()prompt()
56 R.Vijayan/ AP(SG) / SITE / VIT University 2/4/2023
Document Object
Each HTML document loaded into a browser window becomes a
Document object.
The Document object provides access to all HTML elements in a page,
from within a script.
The Document object is also part of the Window object, and can be
accessed through the window.document property.
alert(),prompt(),confirm()
setTimeout(expression/function,millisec)
setInterval(expression/function,millisec)
var x = document.getElementsByTagName("p");
document.getElementById("demo").innerHTML =
"The first paragraph (index 0) is: " + x[0].innerHTML;
var x = document.getElementsByClassName("intro");
document.getElementById("demo").innerHTML =
"The first paragraph (index 0) with class=intro: "+ x[0].innerHTML;
document.querySelector("p").style.backgroundColor = "red";
document.querySelector("h3, h4").style.backgroundColor = "red";
document.querySelector("a[target]");