Document Object
About Document Object

Document object is the part of Window object.

Let See some properties and method of Document Object.

Properties
url,title,referrer,domain etc.

Methods
write(),writeln(),open(),close(),getElementById(),getElementsByName() etc.

URL

This property returns the url of the current page.

Example 1:-

<html>
<body>
<script type="text/javascript">
document.write(document.URL);
</script>
</body>
</html>

Output :-
http://localhost/www/javascriptexample/ten.html

referrer

This property returns url of the current document. but with currect document name.

Example 2:-

<html>
<body>
<script type="text/javascript">
document.write(document.referrer);
</script>
</body>
</html>


Output :-
http://localhost/www/javascriptexample/

title

This property returns the title of the document.

Example 3:-

<html>
<head>
<title>This is title of the document</title>
</head>
<body>
<script type="text/javascript">
document.write(document.title);
</script>
</body>
</html>


Output :-
This is title of the document

domain

This property returns domain name.

Example 4:-

<html>
<body>
<script type="text/javascript">
document.write(document.domain);
</script>
</body>
</html>

Output :-
www.ittrainingonline.co.in

getElementById

This method access the html element(<div>,<b> etc) by id.

Example 5:-

<html>
<head>
<script type="text/javascript">
function getValue()
{
document.getElementById("message").innerHTML="This is test Message";
}
</script>
</head>
<body>
<input name="btn" type="submit" onclick="getValue()" value="Click Here">
<div id="message">Your Message show here</div>
</body>
</html>


Output :-
This is test Message


Previous
Next