Saturday, January 7, 2012

Get properties of a HTML element

Example:
Get properties of a HTML element
<!doctype html>
<head>
<title>Mobile-Web-App: Get Properties of a element </title>
<meta charset="utf-8">

<script>
function myOnLoad(){



var elementToCheck = document.getElementById("checkme");
var arrayProperties = new Array();
var arrayValues = new Array();

//Get all key
for(var key in elementToCheck){
var PropertyValue = key + " : " + elementToCheck[key];
arrayProperties.push(PropertyValue);

//arrayProperties.push(key);


}


arrayinfo = "Number of Properties: " + arrayProperties.length + "<" + "BR/" + ">";

while(arrayProperties.length>0){
arrayinfo += arrayProperties.pop() + "<" + "BR/" + ">";
}

elementProperties = document.getElementById("properties");
elementProperties.innerHTML = arrayinfo;

}

window.onload = myOnLoad;

</script>


</head>
<body>
<h1>Javascript exercise: push/pop of array</h1>
<p>Remark: this example work on Firefox, not on Google Chrome!</p>

<p id="checkme" class="classCheckMe">Check Me!</p>

<p id="properties"></p>

</body>
</html>


Remark: this example work on Firefox, not on Google Chrome!

No comments:

Post a Comment