代替ソリューション(インライン スタイルを定義しない場合、少し複雑ですが)
//document.styleSheets gives the list of available stylesheets for the document
//Here we have only one stylesheet hence document.stylesheets["0"] gives us the only stylesheet
//document.stylesheets["0"].rules gives the object with defined css rules
var rules = document.styleSheets["0"].rules
//iterating over that object to find the object which has css for element ID "uno"
for(property in rules){
if(rules.hasOwnProperty(property)){
if(rules[property].selectorText === "#uno"){
alert(rules[property].style.left);
}
}
}
更新済みファイル
<!DOCTYPE html>
<html>
<img src="pan.jpg" id="uno" width="600" />
<style>
#uno
{
position:relative;
left:100px;
}
</style>
<script>
var rules = document.styleSheets["0"].rules
for(property in rules){
if(rules.hasOwnProperty(property)){
if(rules[property].selectorText === "#uno"){
alert(rules[property].style.left);
}
}
}
</script>
</html>
むしろ、私たちのためにすべてのハードリフティングを行うjqueryを使用してください