javascript object dom

 

JAVASCRIPT OBJECT:-

1.      DOM -DOCUMENT OBJECT MODEL:-

In javascript the dom model is to be acessed using document keyword

There are following implementation used in dom

I.       Display current title

II.    Display number of links

III.  Display number of images

IV. Implementaion of css

V.    Display URL

 

Ex. For displaying current title .

<html>

<head>

<title>login</title>

<script language="JavaScript">

function display()

{

document.getElementById("p1").innerHTML=document.title;

}

</script>

</head>

<body>

<p id="p1"> </p>

<button onclick="display()">submit</button>

</body>

</html>

EX for getting url of the website

<html>

<head>

<script langauge="JavaScript">

function display()

{

document.getElementById("r1").innerHTML=document.URL

}

</script>

</head>

<body>

 

<p id="r1"></p>

<button onclick="display()">submit</button>

</body>

</html>

 

Display number of links

Links are called array in javascripts because it contant s .

<html>

<head>

<script langauge="JavaScript">

function display()

{

document.getElementById("r1").innerHTML=document.links.length

}

</script>

</head>

<body>

<a href ="demo1.html">Demo</a>

<br>

<a href="demo2.html">Demo</a>

<br>

<a href="demo3.html">Demo</a>

<br>

<p id="r1"></p>

<button onclick="display()">submit</button>

</body>

</html>

 

 

 

 

2.      NUMBER OF IMAGES:-

 

 

 

 

<html>

<head>

<script langauge="JavaScript">

function display()

{

document.getElementById("r1").innerHTML=document.images.length;

}

</script>

</head>

<body>

<img src="a.jpg">;

<img src="b.jpg">;

<img src="c.jpg">;

 

<p id="r1"></p>

<button onclick="display()">submit</button>

</body>

</html>

 

 

 

l  BROWSER OBJECT MODELS:-

Browser object model is related to browser environment

BOM is represting window specifier.

Ex. <html>

<head>

<script language="JavaScript">

function display()

{

window.open("http://NRsolution4u.com","mywindow","height=200,width=200");

}

</script>

</head>

<body>

<button onclick="display()">open</button>

</body>

</html>

 

Program for printing the dialog box:-

<html>

<head>

<script language="JavaScript">

function display()

{

window.open("http://NRsolution4u.com","mywindow","height=200,width=200");

}

</script>

</head>

<body>

<button onclick="display()">open</button>

</body>

</html>

Comments

Popular posts from this blog

ViewState for state management

Database joining

INTRODUCTION OF C#