Cheldark
01-21-2012, 11:24 PM
When I click on the image I want to get the "margin-left" value of its block.
In the code below the margin-left is set at 100px.
But when I click on the image the "margin-left" value shows in the "alert" as undefined.
What code changes do I need to get the correct margin-left value?
(Please, no guessing!)
[CODE]
<script type="text/javascript" >
window.onload = function(){
document.getElementById("holder").onclick = showit;
}
function showit( ) {
var marval = document.getElementById("holder").style.marginLeft;
alert(" margin-left= " + marval + " typeof= " + typeof marval);
}
</script>
<style type="text/css">
#holder{
padding: 0px;
margin-left: 100px;
}
</style>
</head>
<body>
<img id="holder" src="anyimage.gif" width="300px" height="200px" />
</body>
[CODE]
In the code below the margin-left is set at 100px.
But when I click on the image the "margin-left" value shows in the "alert" as undefined.
What code changes do I need to get the correct margin-left value?
(Please, no guessing!)
[CODE]
<script type="text/javascript" >
window.onload = function(){
document.getElementById("holder").onclick = showit;
}
function showit( ) {
var marval = document.getElementById("holder").style.marginLeft;
alert(" margin-left= " + marval + " typeof= " + typeof marval);
}
</script>
<style type="text/css">
#holder{
padding: 0px;
margin-left: 100px;
}
</style>
</head>
<body>
<img id="holder" src="anyimage.gif" width="300px" height="200px" />
</body>
[CODE]