Unit-3.2 Java Script DOM
Unit-3.2 Java Script DOM
Prepared by
Dr Komarasamy G
Associate Professor (Grade-2)
School of Computing Science and Engineering
VIT Bhopal University
1
Unit-3 Java Script and JQuery
2
DOM - Document Object Model
• The document object represents the whole html document.
• When html document is loaded in the browser, it becomes a
document object. It is the root element that represents the html
document. It has properties and methods. By the help of document
object, we can add dynamic content to our web page.
• As mentioned earlier, it is the object of window.
window.document
• Is same as
document
https://www.javatpoint.com/document-object-model
Method Description
write("string") writes the given string on the document.
<form name="form1">
Enter Name:<input type="text" name="name"/>
<input type="button" onclick="printvalue()" value="print name"/>
</form>
Methods Description
abs() Returns the absolute value of a number.
acos() Returns the arccosine (in radians) of a number.
ceil() Returns the smallest integer greater than or equal to a
number.
cos() Returns cosine of a number.
floor() Returns the largest integer less than or equal to a number.
log() Returns the natural logarithm (base E) of a number.
max() Returns the largest of zero or more numbers.
min() Returns the smallest of zero or more numbers.
pow() Returns base to the exponent power, that is base exponent.
• Syntax:
var variable_name = new Date();
Example:
var current_date = new Date();
Syntax:
var variable_name = new String(string);
Example:
var s = new String(string);
String Properties
Properties Description
length It returns the length of the string.
prototype It allows you to add properties and methods to an
object.
constructor It returns the reference to the String function that
created the object.
Unit-3 Java Script / Dr Komarasamy G 17
Java Script Built-in Objects
String Methods
Methods Description
charAt() It returns the character at the specified index.
charCodeAt() It returns the ASCII code of the character at the specified
position.
concat() It combines the text of two strings and returns a new string.
indexOf() It returns the index within the calling String object.
match() It is used to match a regular expression against a string.
replace() It is used to replace the matched substring with a new
substring.
search() It executes the search for a match between a regular
expression.
slice() It extracts a session of a string and returns a new string.
split() It splits a string object into an array of strings by separating the
string into the substrings.
toLowerCase() It returns the calling string value converted lower case.
toUpperCase() Returns the calling string value converted to uppercase.
Unit-3 Java Script / Dr Komarasamy G 18
Java Script Built-in Objects
Example : JavaScript String() Methods Program
<html>
<body>
<center>
<script type="text/javascript">
var str = "CareerRide Info";
var s = str.split();
document.write("<b>Char At:</b> " + str.charAt(1)+"<br>");
document.write("<b>CharCode At:</b> " + str.charCodeAt(2)+"<br>");
document.write("<b>Index of:</b> " + str.indexOf("ide")+"<br>");
document.write("<b>Lower Case:</b> " + str.toLowerCase()+"<br>");
document.write("<b>Upper Case:</b> " + str.toUpperCase()+"<br>");
</script>
<center>
</body>
</html>