есть код
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
</head>
<body>
<div id = "hlt"> 10</div>
<div id = "atk"> 1</div>
<div id = "res"></div>
<script>
function on()
{
if (document.getElementById('res').innerHTML.lenght ===undefined)
document.getElementById('res').innerHTML = document.getElementById('hlt').innerHTML - document.getElementById('atk').innerHTML;
else document.getElementById('res').innerHTML = document.getElementById('res').innerHTML - document.getElementById('atk').innerHTML; ;
}
</script>
<button onclick="on()">ha</button>
</body>
</html>
почему второе условие не срабатывает?
---
сработало так
<html>
<head>
<meta charset="utf-8">
<title>test</title>
</head>
<script>
function on()
{
if (document.getElementById('res').innerHTML.length == 0) {
document.getElementById('res').innerHTML = document.getElementById('hlt').innerHTML - document.getElementById('atk').innerHTML;
} else {
document.getElementById('res').innerHTML = document.getElementById('res').innerHTML - document.getElementById('atk').innerHTML;
}
}
</script>
<body>
<div id = "hlt">10</div>
<div id = "atk">1</div>
<div id = "res"></div>
<button onclick="on()">ha</button>
</body>
</html>
то есть проблема в doctype?