HTML - DOM Document applets Property



HTML DOM document applets property used to return a list of all the applets elements within a document but this property is now deprecated. It returns an empty HTMLCollection in all new web browsers.

The length property of applets collection returned the number of applets element in an HTML document. You can use alternate way getElementsByTagName('applet') to get the same results.

Syntax

document.applets;

Return value

It returns an HTMLCollection object which lists all the <applet> elements present in the document.

Methods

Below table shows a list of methods offered by DOM applets collection.

Methods Description
[index] To return the <applet> element from the collection at the given index. Indexing starts from 0 and null is returned if the index is out of bound.
item(index) To return the <applet> element from the collection at the given index. Indexing starts from 0 and null is returned if the index is out of range. It is similar to first method.
namedItem(id) To return the <applet> element from the collection with the given id. Null is returned if the id doesnt exist.

Examples of HTML DOM Document 'applets' Property

The following example illustrates uses of appplets property.

Get number of applet Elements

The following example illustrate to get the number of applet element in the document.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>HTML DOM document applets Property</title>
</head>
<body>
    <p>Click to get the number of applet element</p>
    <button onclick="fun()">Click me</button>
    <p id="applets"></p>
    <script>
        function fun() {
            let x = document.applets.length;
            document.getElementById("applets").innerHTML = x;
        }
    </script>
</body>
</html>

Alternate way to get number of applet Elements

In this example, getElementsByTagName is used as altrnate way to get the number of of <applet> elements

<!DOCTYPE html>
<html lang="en">
<head>
    <title>HTML DOM document applets Property</title>
</head>
<body>
    <applet></applet>
    <p>Click to get the number of applet element</p>
    <button onclick="fun()">Click me</button>
    <p id="applets"></p>
    <script>
        function fun() {
            let num = document.getElementsByTagName("applet").length;
            document.getElementById("applets").innerHTML = num;
        }
    </script>
</body>
</html>

Get Content of First applet Element

In this example, we will get the content of first <applet> using applets [index] method.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>HTML DOM document applets Property</title>
</head>
<body>
    <applet>This is just to show the content of applet tag</applet>
    <p>Click to get the number of applet element</p>
    <button onclick="fun()">Click me</button>
    <p id="applets"></p>
    <script>
        function fun() {
            let num = document.getElementsByTagName("applet")[0].innerHTML;
            document.getElementById("applets").innerHTML = num;
        }
    </script>
</body>
</html>

Supported Browsers

Property Chrome Edge Firefox Safari Opera
applets No No No No No
html_dom.htm
Advertisements