English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

How to Access Object Properties in JavaScript (Example Code)

Example as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>No Title Document</title>
</head>
<body>
	<input type="text" value="I won a prize, won a billion" id="mytext" />
	<script language="javascript">
		/*
		*	1Get the value of the value attribute of the element with id 'mytext'.
		*  2Get the value of the type attribute of the element with id 'mytext'.
		*/
		var txtElement = document.getElementById('mytext');
		//We can access the properties of an object by using the dot notation.
		alert(txtElement.value);
		alert(txtElement.type);
	</script>
</body>
</html>

That's all for the way to access the id object property in JavaScript (example code) brought to you by the editor. I hope everyone will support and cheer for the tutorial~

You May Also Like