There are 3 methods in javascript to get the element(s) in DOM: getElementById(), getElementsByName(), and getElementsByTagName().
If the element has been set a unique element id, we can use getElementById to access it:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ById</title>
<style type="text/css">
<!--
#docid{
height:400px;
width:400px;
background-color:#999;}
-->
</style>
</head>
<body><div id="docid" name="docname" onClick="bgcolor()"></div>
</body>
</html>
<script language="JavaScript" type="text/JavaScript">
<!--
function bgcolor(){
document.getElementById("docid").style.backgroundColor="#0000AA"
}
-->
</script>
And also, we can use getElementsByName to access the element: