Very Important points in Advanced Javascript
Q: How to find no. of DIV tags in a HTML file through Javascript
Suppose you need to know how many DIV
elements there are on the page. In Netscape Navigator, the number of layers
is document.layers.length
. It is not that trivial in Internet Explorer.
You need to use the tags
method of the document.all
array. The tags()
method retrieves all HTML elements of a particular tag from the document.all
array. It returns an array of elements. The following line will populate the given array with all DIV
elements:
var divArray = document.all.tags("DIV");
To find the total number of DIV
elements, just use divArrary.length
. For example, click this link from within Internet Explorer to compute and echo the number of FONT elements in this tip. We just put the following line in the JavaScript section at the top of this page:
var divArray = document.all.tags("FONT");
And the link above is assembled as:
tip is ' + divArray.length)">compute and echo
Q: How to collect and display no. of drives in your system
Suppose you want to do some work with your PC drives. A good starting point will be the drives
collection. It holds a read-only collection of all available drives. A collection is not an array. It is much more difficult to iterate through a collection. You can do it only by using the Enumerator
object. The Enumerator
object supports the following methods: moveFirst()
, moveNext()
, item()
, and atEnd()
. The drives collection supports two properties by its own: count
and item
. The following example demonstrates both drives
collection's properties as well as the Enumarator
's methods:
The enumerator
variable used above is coll
. Be careful not to use the word enum
, as it is apparently reserved but not documented.
Q: How to do folder operations through Javascript
You create an ActiveX File System object by calling ActiveXObject()
with a single argument, Scripting.FileSystemObject
:
myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");
You create a folder object by using the ActiveX's GetFolder()
method:
myFolder = myActiveXObject.GetFolder("c:\\temp");
Here are the Folder
object's properties:
Property | Description |
| Refers to the folder attributes |
| Returns the folder's creation date |
| Returns the folder's last-accessed date |
| Returns the folder's last-modified date |
| Returns the folder's letter drive |
| Returns the folder's |
| Returns |
| Returns the folder name |
| Returns the folder's parent folder name |
| Returns the folder's long path |
| Returns the folder's short name |
| Returns the folder's short path |
| Returns the folder size |
| Returns a |
| Returns the folder type |
Here are the Folder
object's methods:
Method | Description |
| Copies the folder from its parent folder or the root to another folder or the root |
| Removes the folder |
| Moves the folder from its parent folder or the root to another folder or the root |
0 comments
Post a Comment