Displaying all object properties

serkan sendur 0 Tallied Votes 178 Views Share

Sometimes, you need to see what properties does that object have and what values are assigned to them. This snippet does that.

function displayProperties(obj)
{
   var list="";
   for(var p in obj)
   list += p + " : " + obj[p] + "<br>";
   document.write(list);
}

example :

<!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>
    <title>Untitled Page</title>
    <script type="text/javascript">
    function x()
    {
     var list ="";
     for(var p in window.event.srcElement)
     list += p + " : " + window.event.srcElement[p] + "<br>";
      document.write(list);
    }
   
    </script>
</head>
<body>
<a href="#" onclick="x()" >deneme</a>
</body>
</html>