Javascript DOM Element get attribute value

Description

Javascript DOM Element get attribute value

View in separate window

<!DOCTYPE html>
<head>
<title>recipe</title>
<meta charset="utf-8" />
<style>
elem/*  w w w  .  j  a v  a  2 s .c  o m*/
{
  padding: 10px;
  border: 1px solid #000000;
}
</style>
<script type="text/javascript">


window.onload=function() {
   // setting and accessing style properties
   let elem = document.getElementById("elem");
   console.log(elem.id);
   console.log(elem.className);

   let index = elem.getAttribute("data-index");
   console.log(index);

   let role = elem.getAttribute("role");
   console.log(role);

   let field = document.getElementById("field");
   console.log(field.checked);
   console.log(field.value);
   console.log(field.type);

}
</script>
</head>
<body>
<div id="elem" class="test" role="article" data-index="1">
testing
</div>
<form>
<input id="field" type="check" checked="checked" value="test" />
</body>
</html>



PreviousNext

Related