I have a simple question:
Why does not my alert
display the value of the name
attribute of the button? Strangely if I insert the javascript code after the <button>
tag the alert works normally. Here is the code that does not work:
<html>
<head>
<title></title>
</head>
<script type="text/javascript">
var x = document.getElementById('a').name;
function aoba() {
alert(x);
};
</script>
<body>
<button id="a" value="b" onClick="aoba()" name="botão"> BOTÃO 1 </button>
</body>
</html>