Online JavaScript Guide - Methods
Sponsored Links
Methods define functions performed by an object. Making a reference to an object method is similar to referencing its property. Thus, document.write(); calls the write() method of the document object.
Herein lies an important difference in how methods and properties are refered. Methods are always followed by a pair of parenthesis.
Some methods take a value part inside the parenthesis. You would know this by now since you have encountered the write() method in the previous sessions. To refresh your memory here is the code again:
document.write("I Love JavaScript");
The text I Love JavaScript is passed as a value to the write() method of the document object. The main function of this method is to take the value and display it in the browser window.
Different objects have different methods associated with them. The submit() method of a form object causes the form to be submitted. The log() method of the Math object computes the logarithm of the number supplied.
document.myform.submit();
causes myform to be submitted.
Math.log(2);
computes the logarithm of 2. The number is passed to the method inside the parenthesis and is called the argument.
Similarly, in the example before, I Love JavaScript was the argument passed to the write() method.
- What do you think following methods do?
- Math.tan(3);
- Math.sqrt(4);
- document.write("www.webdevelopersnotes.com");
- window.close();
- window.scroll();
- Which method is used to open a new document window? (Take a guess!)
Sponsored Links
Comments, questions, feedback... whatever!
Page contents:
Recent Articles
Recent Blog Posts
Popular Articles
- Hotmail Sign In page
- Create a Hotmail account - Instructions
- Create Gmail address
- Download and install Outlook Express
- Get your free Gmail address
- Outlook Express new version
- Create my own email address
- Browers for Windows list
- Get email address
- Color combinations for web sites and pages
- Create Yahoo ID
